Boost logo

Boost Users :

Subject: Re: [Boost-users] [shared pointer] - question about different types pointing to the same object
From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2009-06-06 19:03:24


On Saturday 06 June 2009, Robert Ramey wrote:
> class base1 {
> virtual ~base1;
> ...
> };
> class derived1 : public base1
> {
> ....
> };
>
> shared_ptr<derived1> pd1(new derived1)
> shared_ptr<base1> pb1(pd);
>
> ? do pd1 and pb1 refer to the same object?

Yes, shared_ptr behaves pretty much the same as raw pointers.

>
> class base2 {
> virtual ~base2;
> ...
> };
> class derived3 : public base1, public base2 {
> ...
> };
>
> shared_ptr<base2> pb2(pd1);
>
> ? do pb1 and pb2 refer to the same object?

No, that wouldn't compile as base2 is not a base class of derived1.




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