设计模式原型模式实现C++

/*********************************
*设计模式--原型模式实现
*C++语言
*Author:WangYong
*Blog:http://www.cnblogs.com/newwy
********************************/
#include <iostream>
using namespace std;
class Prototype
{
	public:
	virtual ~Prototype(){};
	virtual Prototype *Clone() const = 0;	
};
Prototype *Prototype::Clone()const{return 0;}
class ConcretePrototype:public Prototype
{
	public:
	ConcretePrototype(){};
	~ConcretePrototype(){};
	ConcretePrototype(const ConcretePrototype &cp)
	{
		cout<<"ConcretePrototype copy..."<<endl;
	}
	Prototype* Clone()const
	{
		return new ConcretePrototype(*this);	
	}
};
int main()
{
	Prototype *p = new ConcretePrototype();
	Prototype *p1 = p->Clone();
	return 0;
}

原文地址:https://www.cnblogs.com/newwy/p/1855227.html