logo       

Re: polymorphic smart ptr downcast: msg#00223

lib.boost.user

Subject: Re: polymorphic smart ptr downcast


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@xxxxxxxxxxxxx> 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]


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/JjlUgA/vN2EAA/xGHJAA/EbFolB/TM
---------------------------------------------------------------------~->

Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx>


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise