C++ 类的对象属性成员初始化 Posted on 2019-03-03 | Edited on 2019-03-21 | In C++ | Views: 12345678910111213141516171819202122// 构造函数的对象属性初始化列表class Student{private: int id; // 属性对象 // 为属性对象赋值只有两种方式,一种是创建时直接初始化 Teacher t0 = Teacher("lili"); // 另一种是在构造函数后面,挨个为它们初始化 Teacher t1; Teacher t2;public: // 属性对象被要求必须初始化 //Student(int id){ // this->id = id; //} // 初始化时,同时初始化属性对象 Student(int id,char *t1_name):t1(t1_name),t2(t1_name){ this->id = id; }};