Boost logo

Boost Users :

From: Alexandre Carsac (acarsac_at_[hidden])
Date: 2002-11-19 04:52:47


Yes, you are right. Thanks for your quick response. I made a quick test, and it compiles.

I was cheated by the compiler response, the fact i do not use to play with polymorphic's shared_ptr. the instance "a" was not a shared_ptr in my code :

void main()
{
   scoped_ptr<A> a;
   shared_ptr<B> b(new B);
   a = b; // no copy ctor available.
 }

After correction (replacement of scoped_ptr with shared_ptr), it works fine.

Thanks a lot Darin.

 Darin Adler <darin_at_[hidden]> wrote:
On Monday, November 18, 2002, at 09:41 AM, Alexandre Carsac wrote:

> Just wondering if there is some issue to the following problem (a and
> b instance are not in the same block code in true life of course) :
> class A;
> class B : public A ...
>
> void main()
> {
> shared_ptr<A> a;
> shared_ptr<B> b(new B);
> a = b; // what i would like, but it wont compile: no copy ctor
> available
> }

The above is an upcast, not a downcast. It should compile. If not, we
have some sort of shared_ptr bug. But you can't compile a class B that
inherits from A without the definition for class A; we need a real
example here, because there are errors in the shorthand one you
provided.

If you are really talking about polymorphic smart pointer downcasts,
even though your example here shows an upcast, then you probably want
shared_polymorphic_downcast or shared_static_cast. Those are
documented at <http://boost.org/libs/smart_ptr/shared_ptr.htm>.

     -- Darin

---------------------------------
Yahoo! Mail -- Une adresse @yahoo.fr gratuite et en français !

[Non-text portions of this message have been removed]


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