|
Boost Users : |
From: Dhanvi Kapila (boostguy_at_[hidden])
Date: 2006-03-23 22:22:38
Hi Friends,
I have a boost::shared_ptr that stores a pointer to a base class (
class B1 ) and derived classes ( class D1 , class D2 ) both inheriting
from the same Base class.
The Constructors
I have another set of factory classes ( base class : class base1,
derived class : class derv1 & class derv2 ) whoose constructors accepts
boost::shared_ptr of B1.
When constructing derv1: I would like to cast pointer as D1 and ,when
constructing derv2 : cast pointer as D2, but the only way I can access
the class functions is through a shared_ptr to B1.
My question is how do I cast B1 to get D1 and D2 in the constructors for
derv1 and derv2 respectively ?
the pseudo code is
base1* createBase( boost::shared_ptr<B1> b_ptr , int type )
{
if( type == 1 )
return new derv1( boost::polymorphic_downcast<AAAA> b_ptr );
else
return new derv2( boost::polymorphic_downcast<XXXX> b_ptr );
}
what do i write in the place of AAAA & XXXX for the code to wrk ??
Sorry for the long question, but could not express it in any shorter way..
thanks for ur patience and replies
Dhanvi
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