#define _CRT_SECURE_NO_WARNINGS
#include
#include
using namespace std;
class Fruit{
public:
virtual void getFruit() = 0;
};
class Apple : public Fruit {
public:
void getFruit()
{
cout << "我是苹果" << endl;
}
};
class Bannar : public Fruit {
public:
void getFruit()
{
cout << "我是香蕉" << endl;
}
};
class AbFactory {
public:
virtual Fruit* CreateProduct() = 0;
};
class appleFactory : public AbFactory{
public:
Fruit * CreateProduct()
{
return new Apple();
}
};
int main(void)
{
AbFactory *aft = new appleFactory();
Fruit * ft = aft->CreateProduct();
ft->getFruit();
system("pause");
return EXIT_SUCCESS;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)