特点:针对被实例化的类
#include<iostream>
using namespace std;
class Prototype {
public:
virtual ~Prototype();
virtual Prototype* clone()const = 0;
protected:
();
Prototype};
class ConcretePrototype :public Prototype {
public:
()=default;
ConcretePrototype(const ConcretePrototype&obj);//拷贝构造函数
ConcretePrototype~ConcretePrototype()=default;
* clone()const;
Prototype};
::Prototype(){}
Prototype::~Prototype(){}
Prototype
//拷贝构造函数
::ConcretePrototype(const ConcretePrototype& obj) {
ConcretePrototype<< "copy construct" << endl;
cout //...再次进行浅拷贝或者深拷贝等操作
}
* ConcretePrototype::clone()const {
Prototypereturn new ConcretePrototype(*this);
}
int main() {
* prototype = new ConcretePrototype();
Prototype* prototypeOther = prototype->clone();//copy construct
Prototypedelete prototype;
delete prototypeOther;
return 0;
}