Boost logo

Boost Users :

From: John (john_at_[hidden])
Date: 2008-06-24 11:13:03


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.

Frank Mori Hess wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tuesday 24 June 2008 09:43 am, John wrote:
>> 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!
>
> See:
>
> http://lists.boost.org/boost-users/2003/02/2996.php
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFIYQbo5vihyNWuA4URAgX3AJ4sXKFJod/S/HhSgw9pPl+ODY6qLwCbBk9s
> navD7l4mPLsoDQpEezfm1a0=
> =CeuK
> -----END PGP SIGNATURE-----
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net