64,682
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class Human
{
public:
char* name;
unsigned int id;
};
class Worker: public Human
{
public:
Worker():id(1){}//这里出错,error C2614: “Worker”: 非法的成员初始化:“id”不是基或成员
};
class HumanSimpleFactory
{
static Human* CreateHuman(unsigned int tid)
{
Human* hu;
switch(tid)
{
case 1:
hu = new Worker();break;
}
return hu;
}
};
int main()
{
return 0;
}
class Human
{
public:
char* name;
unsigned int id;
Human(unsigned int id_){id = id_}
};
class Worker: public Human
{
public:
Worker():Human(1){}//这里出错,error C2614: “Worker”: 非法的成员初始化:“id”不是基或成员
};
class Worker: public Human
{
public:
Worker()
{
id = 1; // 这里只能赋值,
}
};