为什么对ChildLabourer初始化列表不能写成这样?ChildLabourer(string name, int age):m_strName(name),m_iAge(age)
既然都公有继承了父类,那么子类就应该可以对父类数据成员m_strName和m_iAge进行初始化列表呀,为什么还得用父类的构造函数进行初始化列表 ChildLabourer(string name, int age):Worker(name),Children(age) ???
代码如下:
class ChildLabourer : public Worker,public Children { public: ChildLabourer(string name, int age):m_strName(name),m_iAge(age) { cout << "ChildLabourer" << endl; } ~ChildLabourer() { cout << "~ChildLabourer" << endl; } };