Boost logo

Boost Users :

From: Russell Hind (yg-boost-users_at_[hidden])
Date: 2003-06-20 02:21:11


Drew wrote:
> void Fn(ParentPtr& pObj)
> {
> pObj = ParentPtr(new Parent());
> pObj->m_value = 10;
> }
>
> If I pass the parent pointer, it compiles and works fine. If I pass
> the derived pointer I get:
> > error C2664: 'Fn' : cannot convert parameter 1 from 'DerivedPtr'
> to 'ParentPtr &'
>

You can't assign to a shared_ptr (assuming ParentPtr is a shared_ptr as
the moderator has suggested). You have to call reset on it
e.g.

pObj.reset(new Parent());

HTH

Russell


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