class IPrototype
{
public:
IPrototype(){}
virtual ~IPrototype(){}
virtual IPrototype* Clone() = 0;
};
class Prototype1:public IPrototype
{
public:
Prototype1(){}
~Prototype1(){}
Prototype1(const Prototype1& prototype1)
{
//这里进行深度拷贝
printf("this is a Prototype1\n");
}
public:
IPrototype* Clone()
{
return new Prototype1(*this);
}
};
class Prototype2:public IPrototype
{
public:
Prototype2(){}
~Prototype2(){}
Prototype2(const Prototype2& prototype1)
{
//这里进行深度拷贝
printf("this is a Prototype2\n");
}
public:
IPrototype* Clone()
{
return new Prototype2(*this);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
IPrototype *prototype1=new Prototype1;
IPrototype *prototype11=prototype1->Clone();
delete prototype11;
delete prototype1;
IPrototype *prototype2=new Prototype2;
IPrototype *prototype21=prototype2->Clone();
delete prototype21;
delete prototype2;
getchar();
return 0;
}
转载于:https://my.oschina.net/u/221120/blog/884144