#include<iostream>
using namespace std;
//***当其他类对象作为本类成员,构造时候先构造类对象,再构造自身,析构的顺序与构造相反***
class Phone
{
public:
Phone(string PName)
{
cout << "Phone的构造" << endl;
m_PName = PName;
}
~Phone()
{
cout << "Phone的析构" << endl;
}
string m_PName;
};
class Teacher
{
public:
string m_Name;
Phone m_Phone;
//Phone m_Phone=Phone(PName);
Teacher(string name,string PName) :m_Name(name),m_Phone(PName)
{
cout << "Teacher的构造" << endl;
}
~Teacher()
{
cout << "Teacher的析构" << endl;
}
};
void test09()
{
Teacher t("xiansifan", "1+7");
cout << t.m_Name << "拿着" << t.m_Phone.m_PName << endl;
}
int main()
{
test09();
system("pause");
return 0;
}
网友评论