64,648
社区成员
发帖
与我相关
我的任务
分享
class Factory
{
public:
SingleCore* CreateSingleCore(enum CTYPE ctype)
{
if(ctype == COREA) //工厂内部判断
return new SingleCoreA(); //生产核A
else if(ctype == COREB)
return new SingleCoreB(); //生产核B
else
return NULL;
}
};
class SingleCore
{
public :
void printnum()
{
cout << "base";
}
};
class SingleCoreA:public SingleCore
{
};
class SingleCoreB :public SingleCore
{
};
enum CTYPE
{
COREA,
COREB
};
class Factory
{
public:
SingleCore* CreateSingleCore(enum CTYPE ctype)
{
if (ctype == COREA)//工厂内部判断
return new SingleCoreA();//生产核A
else if(ctype == COREB)
return new SingleCoreB();//生产核B
else
return NULL;
}
};
void main()
{
Factory* fac = new Factory();
SingleCore *f = fac->CreateSingleCore(COREA);
f->printnum();}