帮忙调一下这个程序,谢谢
#include <iostream>
using namespace std;
class Moshou
{
protected:
char name[20]; //魔兽名字
int level; //魔兽级别
public:
virtual ~ Moshou();
virtual Moshou();
};
Moshou::Moshou()
{
}
Moshou::~Moshou()
{
}
class ProduceMoshouA:public Moshou
{
public:ProduceMoshouA();
~ProduceMoshouA();
virtual void Function();
};
ProduceMoshouA::ProduceMoshouA()//初级魔兽
{
cout<<"创建初级奥特曼"<<endl;
}
ProduceMoshouA::~ProduceMoshouA()
{
cout<<"放弃初级奥特曼"<<endl;
}
void ProduceMoshouA::Function()
{
cout<<"创建初级奥特曼的工具"<<endl;
}
ProduceMoshouB::ProduceMoshouB()//中级魔兽
{
cout<<"创建中级奥特曼"<<endl;
}
ProduceMoshouB::~ProduceMoshouB()
{
cout<<"放弃中级奥特曼"<<endl;
}
void ProduceMoshouB::Function()
{
cout<<"创建中级奥特曼的工具"<<endl;
}
ProduceMoshouC::ProduceMoshouC()//高级魔兽
{
cout<<"创建高级奥特曼"<<endl;
}
ProduceMoshouC::~ProduceMoshouC()
{
cout<<"放弃高级奥特曼"<<endl;
}
void ProduceMoshouC::Function()
{
cout<<"创建高级奥特曼的工具"<<endl;
}
class SimpleFactory
{
public:SimpleFactory(){}
~SimpleFactory(){}
Moshou *AdoptMoshou(int MoshouType);
Moshou *AdoptMoshouA();
Moshou *AdoptMoshouB();
};
Moshou *SimpleFactory::AdoptMoshou(int MoshouType=0)
{
Moshou *p=0;
switch (MoshouType)
{
case 0:p=new ProduceMoshouA();break;
case 1:p=new ProduceMoshouB();break;
case 2:p=new ProduceMoshouC();break;
default:cout<<"游戏失败"<<endl;break;
return p;
}
}
Moshou *SimpleFactory::AdoptMoshouA()
{
return new ProduceMoshouA();
}
Moshou *SimpleFactory::AdoptMoshouB()
{
return new ProduceMoshouB();
}
Moshou *SimpleFactory::AdoptMoshouC()
{
return new ProduceMoshouC();
}
int main()
{
SimpleFactory sf;
Moshou* p=sf.AdoptMoshouA();
P->Function();
delete p;
p=sf.AdoptMoshouB();
P->Function();
delete p;
p=sf.AdoptMoshouC();
P->Function();
delete p;
return 0;
}