⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prototype.cpp

📁 设计模式
💻 CPP
字号:
namespace DesignPattern_Prototype
{
	//定义抽象基类class Prototype
	class Prototype	{
	public:
		virtual Prototype* Clone() = 0 ;
	} ;
	//定义 class ConcretePrototype1
	class ConcretePrototype1 : public Prototype
	{
	public:
		virtual Prototype* Clone()
		{
			ConcretePrototype1 *p = new ConcretePrototype1() ;
			*p = *this ; //复制对象
			return p ;
		}
	} ;
	//定义class ConcretePrototype2
	class ConcretePrototype2 : public Prototype
	{
	public:
		virtual Prototype* Clone()
		{
			ConcretePrototype2 *p = new ConcretePrototype2() ;
			*p = *this ; //复制对象
			return p ;
		}
	} ;
}
void main()
{
	using namespace DesignPattern_Prototype ;
	ConcretePrototype1 *obj1 = new ConcretePrototype1() ;//构造原型对象1
	ConcretePrototype2 *obj2 = new ConcretePrototype2() ;//构造原型对象2
	Prototype *newobj1 = obj1->Clone() ;//克隆对象1
	Prototype *newobj2 = obj2->Clone() ;//克隆对象2
	//使用复制出的对象newobj1和newobj2……………..
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -