20 Jun
2003
20 Jun
'03
7:21 a.m.
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