#include <iostream>
#include <string>
using namespace std;
class Prototype {
public:
virtual Prototype* CreateClone() = 0;
virtual void SetStatus(int status) {}
virtual int GetStatus() {}
};
class Implement : public Prototype {
public:
Implement() {
m_status = 0;
}
Implement(const Implement& imp) {
m_status = imp.m_status;
}
virtual Prototype* CreateClone() {
return new Implement(*this);
}
virtual void SetStatus(int status) {
m_status = status;
}
virtual int GetStatus() {
return m_status;
}
private:
int m_status;
};
int main() {
Prototype *obj = new Implement;
obj->SetStatus(123);
Prototype *clone = obj->CreateClone();
cout << clone->GetStatus() << endl;
// delete はどうするか。。
// obj はここで new してるし。
return 0;
}
参考サイト
最終更新:2011年11月13日 18:22