
24 Jun
2008
24 Jun
'08
1:52 p.m.
John skrev:
This pattern/idiom is well-established:
struct A { virtual A* clone () = 0; };
struct B : public A { virtual B* clone (); };
But the above does not work when the pointers A* and B* are replaced by shared_ptr<A> and shared_ptr<B>:
struct A { virtual shared_ptr<A> clone () = 0; };
struct B : public A { virtual shared_ptr<B> clone (); };
Is there a workaround? Another way to solve the same problem? Thanks!
Well, don't use shared_ptr here. A newly created clone is not shared, and it makes the interface less usable in other context to return a shared ptr here. -Thorsten