类对象作为类成员的案例
类对象作为类成员,
构造顺序先将类对象一一构造,然后构造自己;
析构顺序与构造的顺序相反,先析构自己,再析构对象。
class Phone {
public:
Phone() {
cout << "Phone's default constructor." << endl;
}
Phone(string name) {
m_PhoneName = name;
cout << "Phone's parameterized constructor." << endl;
}
~Phone() {
cout << "Phone's destructor." << endl;
}
string m_PhoneName;
};
class Game {
public:
Game() {
cout << "Game's default constructor." << endl;
}
Game(string name) {
m_GameName = name;
cout << "Game's parameterized constructor." << endl;
}
~Game() {
cout << "Game's destructor." << endl;
}
string m_GameName;
};
class Person06 {
public:
Person06() {
cout << "Person's default constructor." << endl;
}
Person06(st