#include <iostream>
#include <string>
using namespace std;
class Prototype
{
public:
virtual ~Prototype(){}
virtual Prototype *clone(string name, int age) =0;
virtual void getInfo() =0;
virtual void setName(string name) =0;
virtual void setAge(int age) =0;
};
class Person : public Prototype
{
public:
Person(string name, int age)
{
this->name = name;
this->age = age;
}
Person(Person &rth)
{
this->name = rth.name;
this->age = rth.age;
}
Prototype *clone(string name, int age)
{
Prototype *pTmp = new Person(*this);
pTmp->setName(name);
pTmp->setAge(age);
return pTmp;
}
void getInfo()
{
cout<<"name :"<<name<<" ,age :"<<age<<endl;
}
void setName(string name)
{
this->name = name;
}
void setAge(int age)
{
this->age = age;
}
private:
string name;
int age;
};
int main()
{
Person tom("tom", 22);
tom.getInfo();
Prototype *jim = tom.clone("jim", 20);
jim->getInfo();
delete jim;
return 0;
}