/*prototype.h*/#ifndef Prototype_h#define prototype_hClass prototype{ Public:Virtual~Prototype();VirtualPrototype *clone ()Const=0;protected:Prototype();Private:};class Concreteprototype: Publicprototype{ Public:Concreteprototype(); Concreteprototype (ConstConcreteprototype &CP); ~concreteprototype (); Prototype *clone ()Const;protected:Private:};#endif
/*prototype.cpp*/ #include "Prototype.h" #include <iostream> Prototype::P rototype () {}prototype::~prototype () {}concreteprototype::concreteprototype () {}concreteprototype::~ Concreteprototype () {}concreteprototype::concreteprototype (const Concreteprototype &cp) {std :: cout < < "Concreteprototype ..." <<std :: Endl;} Prototype *concreteprototype::clone () const {return< /span> new concreteprototype (*this );}
/*main.cpp*/#include "Prototype.h"#include <iostream>int main(){ Prototype *p=new ConcretePrototype(); Prototype *p1=p->Clone(); return0;}
Prototype pattern (prototype mode)