注意:
构造与析构的顺序
#include<iostream>
#include<string>
using namespace std;
class Phone
{
public:
Phone(string name)
{
pName = name;
cout << "make phone" << endl;
}
~Phone()
{
cout << "del phone" << endl;
}
string pName;
};
class Child
{
public:
Child(string name,string pname):cName(name),p1(pname)
{
cout << "make Child" << endl;
}
~Child()
{
cout << "del Child" << endl;
}
Phone p1;
string cName;
};
/*
make phone
make Child
del Child
del phone
*/
void test_11()
{
Child c("tom","apple");
cout << "name = " << c.cName << " phone = " << c.p1.pName << endl;
}
int main(){
test_11();
}