标签:group cfa 访问 info 形参 amp 开发者 权限 成员
class CAnimal { public: CAnimal() : mGroup(0) { cout << "CAnimal()" << endl; } CAnimal(int group) : mGroup(group) { cout << "CAnimal(" << group << ")" << endl; } CAnimal(const CAnimal &other) : mGroup(other.mGroup) { cout << "CAnimal(const CAnimal &other)" << endl; } public: void info() { cout << "CAnimal.mGroup = " << mGroup << endl; } private: int mGroup; }; class CDog : public CAnimal { public: CDog() { cout << "CDog()" << endl; } CDog(int price) : CAnimal(1), mPrice(price) { cout << "CDog(" << mPrice << ")" << endl; } CDog(const CDog &other) : CAnimal(other), mPrice(other.mPrice) { cout << "CDog(const CDog &other)" << endl; } public: void info() { CAnimal::info(); cout << "CDog.mPrice = " << mPrice << endl; } private: int mPrice; }; class CCat : public CAnimal { public: CCat() { cout << "CCat()" << endl; } CCat(int price) : CAnimal(2), mPrice(price) { cout << "CCat(" << mPrice << ")" << endl; } CCat(const CCat &other) : CAnimal(other), mPrice(other.mPrice) { cout << "CCat(const CCat &other)" << endl; } public: void info() { CAnimal::info(); cout << "CCat.mPrice = " << mPrice << endl; } private: int mPrice; }; class CPig : public CAnimal { public: CPig() { cout << "CPig()" << endl; } CPig(int price) : CAnimal(3), mPrice(price) { cout << "CPig(" << mPrice << ")" << endl; } CPig(const CPig &other) : CAnimal(other), mPrice(other.mPrice) { cout << "CPig(const CPig &other)" << endl; } public: void info() { CAnimal::info(); cout << "CPig.mPrice = " << mPrice << endl; } private: int mPrice; }; class CDonkey : public CAnimal { public: CDonkey() { cout << "CDonkey()" << endl; } CDonkey(int price) : CAnimal(4), mPrice(price) { cout << "CDonkey(" << mPrice << ")" << endl; } CDonkey(const CDonkey &other) : CAnimal(other), mPrice(other.mPrice) { cout << "CDonkey(const CDonkey &other)" << endl; } public: void info() { CAnimal::info(); cout << "CDonkey.mPrice = " << mPrice << endl; } private: int mPrice; }; class CHorse : public CAnimal { public: CHorse() { cout << "CHorse()" << endl; } CHorse(int price) : CAnimal(5), mPrice(price) { cout << "CHorse(" << mPrice << ")" << endl; } CHorse(const CHorse &other) : CAnimal(other), mPrice(other.mPrice) { cout << "CHorse(const CHorse &other)" << endl; } public: void info() { CAnimal::info(); cout << "CHorse.mPrice = " << mPrice << endl; } private: int mPrice; };
class CFarmLand { public: CFarmLand() { cout << "CFarmLand()" << endl; } CFarmLand(int area) : mArea(area) { cout << "CFarmLand(" << mArea << ")" << endl; } CFarmLand(const CFarmLand &other) : mArea(other.mArea) { cout << "CFarmLand(const CFarmLand &other)" << endl; } public: void info() { cout << "mArea = " << mArea << endl; } public: int mArea; }; class CFarm : public CFarmLand { public: CFarm() { cout << "CFarm()" << endl; } CFarm(int kind) : mKind(kind), mDog(300), mCat(100), mPig(500), CFarmLand(800) { cout << "CFarm(" << mKind << ")" << endl; } CFarm(const CFarm &other) : mKind(other.mKind), CFarmLand(other) { cout << "CFarm(const CFarm &other)" << endl; } public: void info() { CFarmLand::info(); cout << "mKind = " << mKind << endl; mPig.info(); mDog.info(); mCat.info(); } private: int mKind; private: CPig mPig; CDog mDog; CCat mCat; };
void construct() { { cout << "-----1-start-----" << endl; cout << "-----construct-----" << endl; CFarm farm; cout << "-----info-----" << endl; farm.info(); cout << "-----1-end-----" << endl; } { cout << "-----2-start-----" << endl; cout << "-----construct-----" << endl; CFarm farm(3); cout << "-----info-----" << endl; farm.info(); cout << "-----2-end-----" << endl; } }
-----1-start----- -----construct----- CFarmLand() CAnimal() CPig() CAnimal() CDog() CAnimal() CCat() CFarm() -----info----- mArea = 0 mKind = 0 CAnimal.mGroup = 0 CPig.mPrice = 0 CAnimal.mGroup = 0 CDog.mPrice = -587201213 CAnimal.mGroup = 0 CCat.mPrice = 32767 -----1-end----- -----2-start----- -----construct----- CFarmLand(800) CAnimal(3) CPig(500) CAnimal(1) CDog(300) CAnimal(2) CCat(100) CFarm(3) -----info----- mArea = 800 mKind = 3 CAnimal.mGroup = 3 CPig.mPrice = 500 CAnimal.mGroup = 1 CDog.mPrice = 300 CAnimal.mGroup = 2 CCat.mPrice = 100 -----2-end-----
class CAnimal { public: CAnimal() { cout << "CAnimal()" << endl; } CAnimal(int group = 0) : mGroup(group) { cout << "CAnimal(" << group << ")" << endl; } CAnimal(int group = 0, int subGroup = 1) : mGroup(group), mSubGroup(subGroup) { cout << "CAnimal(" << group << ", " << subGroup << ")" << endl; } private: int mGroup; int mSubGroup; };
class CAdvanceFarm : public CFarm { private: CHorse mHorse; CDonkey mDonkey; };
CAdvanceFarm() : CFarm(), mHorse(), mDonkey() {}
void construct() { cout << "-----construct-----" << endl; CAdvanceFarm farm; }
-----construct----- CFarmLand() CAnimal() CPig() CAnimal() CDog() CAnimal() CCat() CFarm() CAnimal() CHorse() CAnimal() CDonkey()
void copyConstruct() { { cout << "-----1-start-----" << endl; cout << "-----construct-----" << endl; CFarm farm(3); cout << "-----info-----" << endl; farm.info(); cout << "-----copy construct-----" << endl; CFarm copyFarm = farm; cout << "-----info-----" << endl; copyFarm.info(); cout << "-----1-end-----" << endl; } }
-----1-start----- -----construct----- CFarmLand(800) CAnimal(3) CPig(500) CAnimal(1) CDog(300) CAnimal(2) CCat(100) CFarm(3) -----info----- mArea = 800 mKind = 3 CAnimal.mGroup = 3 CPig.mPrice = 500 CAnimal.mGroup = 1 CDog.mPrice = 300 CAnimal.mGroup = 2 CCat.mPrice = 100 -----copy construct----- CFarmLand(const CFarmLand &other) CAnimal() CPig() CAnimal() CDog() CAnimal() CCat() CFarm(const CFarm &other) -----info----- mArea = 800 mKind = 3 CAnimal.mGroup = 0 CPig.mPrice = 0 CAnimal.mGroup = 0 CDog.mPrice = 855688896 CAnimal.mGroup = 0 CCat.mPrice = 32767 -----1-end-----
class CAdvanceFarm : public CFarm { private: CHorse mHorse; CDonkey mDonkey; };
CAdvanceFarm(const CAdvanceFarm &other) : CFarm(other), mHorse(other.mHorse), mDonkey(other.mDonkey) {}
void copyConstruct() { cout << "-----construct-----" << endl; CAdvanceFarm farm; cout << "-----copy construct-----" << endl; CAdvanceFarm copyFarm = farm; }
-----construct----- CFarmLand() CAnimal() CPig() CAnimal() CDog() CAnimal() CCat() CFarm() CAnimal() CHorse() CAnimal() CDonkey() -----copy construct----- CFarmLand(const CFarmLand &other) CAnimal() CPig() CAnimal() CDog() CAnimal() CCat() CFarm(const CFarm &other) CAnimal(const CAnimal &other) CHorse(const CHorse &other) CAnimal(const CAnimal &other) CDonkey(const CDonkey &other)
class CAnimal { public: CAnimal() : mGroup(0) { cout << "CAnimal()" << endl; } CAnimal(int group) : mGroup(group) { cout << "CAnimal(" << group << ")" << endl; } CAnimal(CAnimal &other) : mGroup(other.mGroup) { cout << "CAnimal(const CAnimal &other)" << endl; } public: void info() const { cout << "CAnimal.mGroup = " << mGroup << endl; } private: int mGroup; };
void copyConstruct() { { cout << "-----1-start-----" << endl; cout << "-----construct-----" << endl; const CAnimal animal(1); cout << "-----info-----" << endl; animal.info(); cout << "-----copy construct-----" << endl; //CAnimal copyAnimal = animal; cout << "-----1-end-----" << endl; } }
标签:group cfa 访问 info 形参 amp 开发者 权限 成员
原文地址:http://blog.csdn.net/mardax/article/details/51617455