1 #include <iostream> 2 using namespace std; 3 4 class base 5 { 6 public: 7 int x; 8 base():x(3){} 9 virtual base* clone()=0; 10 virtual ~base(){} 11 void f(){ 12 cout<<x<<endl; 13 } 14 }; 15 16 17 class derieved : public base 18 { 19 public: 20 21 derieved(){} 22 virtual base* clone(){ 23 return new derieved(*this); 24 } 25 }; 26 27 int main() 28 { 29 base* kaka=new derieved(); 30 base* kaka_copy=kaka->clone(); 31 kaka_copy->f(); 32 return 0; 33 }