引用的类比被引用的类后构造,先析构
#include <iostream>
#include <string>
using namespace std;
class Phone
{
public:
string _PhoneName;
Phone(string name)
{
_PhoneName = name;
}
~Phone()
{
cout << "析构Phone这个函数" << endl;
}
};
class Person
{
public:
string _Name;
Phone _Phone;
Person(string name, string PhoneName) :_Name(name), _Phone(PhoneName)
{
}
~Person()
{
cout << "析构Person这个函数" << endl;
}
};
void test()
{
Person p("李云龙","phone");
cout << p._Name << endl;
cout << p._Phone._PhoneName << endl;
}
int main()
{
test();
return 0;
}