#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
class WorkExperience
{
};
class ProtoType
{
public:
ProtoType() {}
virtual ~ProtoType() {}
virtual ProtoType* Clone() = 0;
virtual void Display() = 0;
};
class Resume : public ProtoType
{
private:
string name;
int age;
string sex;
public:
Resume(string name, int age, string sex)
{
this->name = name;
this->age = age;
this->sex = sex;
}
Resume(const Resume& resume)
{
this = new Resume;
}
void ShowInfo()
{
cout << this->name << "\t";
cout << this->age << "\t";
cout << this->sex << "\t";
cout << endl;
}
ProtoType* Clone()
{
return new Resume(*this);
}
void Display()
{
ShowInfo();
}
};
int main()
{
ProtoType *pResume1 = new Resume("ÕÅÈý", 30, "ÄÐ");
pResume1->Display();
ProtoType *pResume2 = pResume1->Clone();
pResume2->Display();
return 0;
}
原型模式之C++实现