How to convert shared_ptr to pointer?
I have shared_ptr<int> variable. I need to pass a int* pointer to a function call. How to pass shared_ptr<int> as int *? -- View this message in context: http://boost.2283326.n4.nabble.com/How-to-convert-shared-ptr-to-pointer-tp46... Sent from the Boost - Users mailing list archive at Nabble.com.
On 3 January 2013 17:21, young
I have shared_ptr<int> variable. I need to pass a int* pointer to a function call. How to pass shared_ptr<int> as int *?
Look at the manual [1] and search for get() member and get_pointer free function. [1] http://www.boost.org/doc/libs/1_52_0/libs/smart_ptr/shared_ptr.htm Best regards, -- Mateusz Loskot, http://mateusz.loskot.net
On Thu, Jan 3, 2013 at 11:27 AM, Igor R
I have shared_ptr<int> variable. I need to pass a int* pointer to a function call. How to pass shared_ptr<int> as int *?
shared_ptr<int> p; p.get();
But make sure the function doesn't store this raw pointer, otherwise it would defeat the whole purpose of shared_ptr.
More specifically, make sure that you have a shared_ptr<> in scope for the entire time the raw pointer is in scope. Failure to do so will surely result in badness at some point. -- Chris Cleeland
participants (5)
-
Chris Cleeland
-
Igor R
-
Jookia
-
Mateusz Loskot
-
young