9 Jun
2010
9 Jun
'10
1:33 p.m.
boost::shared_ptr<a> Ptr(new a()); I need to pass this pointer as an argument to function (MyFunc) which access this as a reference
void MyFunc(a& ref) { }
Now I am calling the function like this
MyFunc(*Ptr);
But this causes the "Ptr" to destroy early (I am using this for an
Ptr is destroyed when it goes out of scope. If there no more shared_ptr's to this object - it gets deleted as well. It's not a good idea to store references or raw pointers to an object, which is managed by shared_ptr.