#include<iostream>
using namespace std;
class Phone
{
public:Phone(string pname){m_pname=pname;cout<<"phone的构造函数调用"<<endl;}~Phone(){cout<<"Phone的析构函数调用"<<endl;}string m_pname;
};
class Person
{
public:Person(string name,string pname):m_name(name),m_phone(pname){cout<<"person的构造函数调用"<<endl;}string m_name;Phone m_phone;~Person(){cout<<"Person的析构函数调用"<<endl;}
};
void test01()
{Person p("张三","苹果");cout<<p.m_name<<"拿着:"<<p.m_phone.m_pname<<endl;
}
int main()
{test01();
}
比如class A中有class B,则先调用class B的构造函数,再调用class A的构造函数,先调用class A的析构函数,再调用class B的析构函数。class B先来后去。