//Prototype.h
#ifndef _PROTOTYPE_H
#define _PROTOTYPE_H
class Prototype
{
public:
virtual Prototype * clone() const = 0;
virtual ~Prototype();
protected:
Prototype();
};
class ConcretePrototype:Prototype
{
public:
ConcretePrototype();
ConcretePrototype(const ConcretePrototype & prt);
Prototype * clone() const;
~ConcretePrototype();
};
#endif
//Prototype.cpp
#include "Prototype.h"
#include <iostream>
using namespace std;
Prototype::Prototype()
{}
Prototype::~Prototype()
{}
ConcretePrototype::ConcretePrototype()
{}
ConcretePrototype::ConcretePrototype(const ConcretePrototype & prt)
{
cout<<"ConcretePrototype copy ..."<<endl;
}
ConcretePrototype::~ConcretePrototype()
{}
Prototype * ConcretePrototype::Clone()
{
return new ConcretePrototype(*this);
}
//main.cpp
#include "Prototype.h"
#include <iostream>
using namespace std;
void main(int agrc, char * argv[])
{
Prototype *p = new ConcretePrototype();
Prototype *p1 = p->clone();
return 0;
}