-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 24 June 2008 11:13 am, John wrote:
Thanks, I did see that in the archives before I posted. Please correct me if I'm wrong, but the code from 2003 doesn't provide a solution, since the clone() method is not virtual. i.e., you can't do this with it:
shared_ptr<A> a = foo(); shared_ptr<A> a2 = a->clone ();
which is the goal of the pattern.
The free function solution mentioned in the post calls the virtual do_clone. The virtual do_clone always returns a shared_ptr to the base class, and the template free function downcasts it. The free function has to be a friend, (or do_clone public). -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIYRpY5vihyNWuA4URAprZAKCUckkFLIb8X50siGh8XR1qW5OuYwCfTj1P wpGOYLt+zYm9oFE+IPT3OR8= =dBMq -----END PGP SIGNATURE-----