|
Boost Users : |
Subject: Re: [Boost-users] passing a shared pointer
From: Igor R (boost.lists_at_[hidden])
Date: 2010-06-09 09:33:57
> 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.
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