#include "stdafx.h" #include <iostream> #include <string> class CClone { public: virtual ~CClone() {} public: virtual CClone* Clone() = 0; virtual void Print() = 0; }; class CDerived : public CClone { public: CDerived() { } void SetName(const std::string& strName) { m_strName = strName; } public: virtual CClone* Clone() { CDerived* pClone = new CDerived(); pClone->m_strName = this->m_strName; return pClone; } virtual void Print() { std::cout << m_strName << std::endl; } private: std::string m_strName; }; int _tmain(int argc, _TCHAR* argv[]) { CDerived Obj; Obj.SetName("Hello, everyone"); Obj.Print(); CClone* pClone = Obj.Clone(); pClone->Print(); delete pClone; return 0; }