1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include<iostream> using namespace std; class Phone { public: string m_pName; string m_pNumber; Phone(string pName,string pNumber):m_pName(pName),m_pNumber(pNumber) { cout << "Phone的构造函数调用。" << endl; } ~Phone() { cout << "Phone的析构函数调用。" << endl; } }; class Person { public: string m_name; Phone m_phone; Person(string name, string pName, string pNumber) :m_name(name), m_phone(pName, pNumber) { cout << "Person的构造函数调用。" << endl; } ~Person() { cout << "Person的析构函数调用。" << endl; } }; void test01() { Person p("张三","iPhone 7","123456"); cout << "姓名:" << p.m_name << " 手机型号:" << p.m_phone.m_pName << "手机号码:" << p.m_phone.m_pNumber << endl; } int main() { test01(); return 0; }
|