新手学习C++,请指导一下程序
程序代码:
#include <iostream> using namespace std; enum BREED {GOLDEN, CAIRN, DANDIE, SHETLAND, DOBERMAN, LAB}; class Mammal { public: Mammal():itsAge(2),itsWeight(5){}//initialize itsAge=2,itsWeight=5 ~Mammal(){} int GetAge()const{return itsAge;} void SetAge(int age){itsAge= age;} int GetWeight()const{return itsWeight;} void SetWeight(int weight){itsWeight = weight;} void Speek()const{cout<<"Mammal sound!\n";} void Sleep()const{cout<<"shhh. I'm sleeping.\n";} protected: int itsAge; int itsWeight; }; class Dog:public Mammal { public: Dog():itsBreed(GOLDEN){}//what it means? ~Dog(){} BREED GetBreed()const{return itsBreed;} void SetBreed(BREED breed){itsBreed = breed;} void WagTail()const{cout<<"Tail wagging...\n";} void BegForFood()const{cout<<"Begging for food...\n";} protected: BREED itsBreed; }; int main() { Dog Fido; Fido.Speek(); Fido.WagTail(); cout<<"Fido is "<<Fido.GetAge()<<" years old."<<endl; return 0; }
-------------------------------------------------------
帮忙说一下Dog():itsBreed(GOLDEN){}到底有什么用啊。我就知道这是构造函数,用来初始化类对象的。itsBreed(GOLDEN)就是初始化,相当于itsBreed = GOLDEN;但是没发觉这个在程序中的用处啊。。。