
5 Dec
2008
5 Dec
'08
1:14 a.m.
Hicham Mouline wrote:
Like this?
class C : public boost::noncopyable { public: ... clone() const { ... } private: C( const C& rhs ) { .... } };
... instance c1 of C exists here ....
What possible return types of clone() const are possible? .A native reference .An auto_ptr
To be honest, I'm not sure myself of how it would be used...
In my experience, the major reason for a clone() function is to allow "virtual copy constructors". struct Base { virtual Base *clone() const = 0; //You might return auto_pointer<Base> or shared_ptr<Base> instead }; struct Derived1 : public Base { Base *clone() const {return new Derived1();} }; struct Derived2: public Base { Base *clone() const {return new Derived2();} };