Hi, I have a shared pointer like this class a { }; 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 asynchronous-ASIO- operation) How can I do this right? Thanks a lot, Lloyd ______________________________________ Scanned and protected by Email scanner
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.
class a
{
};
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(Ptr ptrToObjWhichWontBeDestroyedWhenOriginalGoesOutOfScope) { } ****************************************************************************** "This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you." Interactive Transaction Solutions Ltd (2473364 England) Registered Office: Systems House, Station Approach Emsworth PO10 7PW ********************************************************************** This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
participants (3)
-
Igor R
-
Lloyd
-
Patrick Loney