网站建设与管理期末试卷,手机端怎么变成电脑端,购物网站建设平台,哪里可以做网站类对象作为类成员 类中的成员可以是另一个类的对象。该成员成为对象成员当其它类的对现作为本类的成员#xff0c;先构造其它类对象#xff0c;再构造本身。当其它类的对现作为本类的成员#xff0c;先析构自身#xff0c;再析构其它类对象。
code:#includeiostream先构造其它类对象再构造本身。当其它类的对现作为本类的成员先析构自身再析构其它类对象。
code:#includeiostreamusing namespace std;#includecircle.hclass Phone{public:string brand;Phone(string ref_brand){brand ref_brand;cout Phone的构造函数 endl;}~Phone(){cout Phone的析构函数 endl;}};class Person{public:string name;Phone phone;// 初始化列表// phone(ref_brand): 识别为 Phone phoneref_brandPerson(string ref_name, string ref_brand) :name(ref_name), phone(ref_brand){cout Person的构造函数 endl;}~Person(){cout Person的析构函数 endl;}};void test(){Person p1(ZhangSan, Apple);cout p1.name 的手机是: p1.phone.brand endl;}void main(){test();system(pause);}result:Phone的构造函数Person的构造函数ZhangSan的手机是: ApplePerson的析构函数Phone的析构函数