/*Prototype.h*/
#ifndef PROTOTYPE_H
#define PROTOTYPE_H
class Prototype
{
public:
virtual ~Prototype();
virtual Prototype *Clone() const=0;
protected:
Prototype();
private:
};
class ConcretePrototype:public Prototype
{
public:
ConcretePrototype();
ConcretePrototype(const ConcretePrototype &cp);
~ConcretePrototype();
Prototype *Clone() const;
protected:
private:
};
#endif
/*Prototype.cpp*/
#include "Prototype.h"
#include <iostream>
Prototype::Prototype()
{
}
Prototype::~Prototype()
{
}
ConcretePrototype::ConcretePrototype()
{
}
ConcretePrototype::~ConcretePrototype()
{
}
ConcretePrototype::ConcretePrototype(const ConcretePrototype &cp)
{
std::cout<<"ConcretePrototype..."<<std::endl;
}
Prototype *ConcretePrototype::Clone() const
{
return new ConcretePrototype(*this);
}
/*main.cpp*/
#include "Prototype.h"
#include <iostream>
int main()
{
Prototype *p=new ConcretePrototype();
Prototype *p1=p->Clone();
return 0;
}
时间: 2024-11-04 00:13:08