#include <iostream>
using namespace std;
//
class CResume
{
public:
CResume(const char* pName)
{
if(NULL == pName)
{
m_pName = new char[1];
m_pName[0] = '\0';
}
else
{
m_pName = new char[strlen(pName)+1];
strcpy(m_pName,pName);
}
}
CResume(const CResume &r)
{
m_pName = new char[strlen(r.m_pName)+1];
strcpy(m_pName,r.m_pName);
}
~CResume()
{
if(m_pName)
{
delete []m_pName;
m_pName = NULL;
}
}
CResume* Clone() { return new CResume(*this); }
void Show() { cout<<"Resume Name:"<<m_pName<<endl; }
private:
char *m_pName;
};
//
void main()
{
CResume *pResume = new CResume("A");
pResume->Show();
CResume *pA = pResume->Clone();
delete pResume;
pA->Show();
delete pA;
}
设计模式4:原型模式【创建型】
最新推荐文章于 2024-09-22 11:49:16 发布