12345
class Object { public: Object(); virtual Object clone() const; };
123456789101112
class Card : public Object { public: Card(); virtual Object clone() const; virtual int getValue() const; }; Object Card::clone() const { Card card; card.copy(*this); return card; }
Card::clone()
Card
12
Card o; ((Card) o.clone()).getValue()
1234
Card* o = new Card; Object* obj = NULL; obj = dynamic_cast <Object*> (o.clone()); obj->/*...*/
123
Card *c=(Card *)obj.clone(); /*...*/=c->getValue(); delete c;
/*...*/=((Card *)obj)->getValue();