I'm on Ubuntu 14.04 using GCC 4.8.4, and I have code similar to the following:
std::shared_ptr<MyClass> my_shared_object = set elsewhere...
MyFunction(*my_shared_object);
Where the signature is MyFunctionas follows:
void MyFunction(const MyClass& my_object)
Full code can be found here.
However, I found that my_object is actually out of scope in the context MyFunction. My thought was that it my_shared_objectwould release its content only after leaving the scope, which means after returning MyFunction. I am not sure that I am either misunderstanding std::shared_ptr, or maybe this is a GCC error.
I think the question boils down to: when I look for std :: shared_ptr, does it guarantee that it std::shared_ptrwill persist until dereferencing is used?
source
share