boost::shared_ptr and casting operation
Hi, can someone please provide me an elegant way to solve the current problem. class A; class B : public A; boost::shared_ptr<A> pA; boost::shared_ptr<B> pB; Would like to cast pB to pA with a construct like the *static_cast* but that ain't really pretty ! Thanks in advance Michael
Michael Bradley Jr wrote:
class A; class B : public A;
boost::shared_ptr<A> pA; boost::shared_ptr<B> pB;
Would like to cast pB to pA with a construct like the *static_cast* but that ain't really pretty !
? Won't it just implicitly cast? e.g. boost::shared_ptr<A> pA2 = pB;
Michael Bradley Jr wrote:
Hi,
can someone please provide me an elegant way to solve the current problem.
class A; class B : public A;
boost::shared_ptr<A> pA; boost::shared_ptr<B> pB;
Would like to cast pB to pA with a construct like the *static_cast* but that ain't really pretty !
It implicitly casts except on some backward compilers, where it can fail. See the boost::shared_ptr documentation under the introduction, 6th paragraph.
On Thursday 03 January 2008 11:16, Michael Bradley Jr wrote:
Hi,
can someone please provide me an elegant way to solve the current problem.
class A; class B : public A;
boost::shared_ptr<A> pA; boost::shared_ptr<B> pB;
Would like to cast pB to pA with a construct like the *static_cast* but that ain't really pretty !
Is there some reason you can't use static_pointer_cast() ? -- Frank
participants (4)
-
Edward Diener
-
Frank Mori Hess
-
Michael Bradley Jr
-
Nat Goodspeed