CC'd to the correct newsgroup.>>how do I convert back a boost shared_ptr into a reference?return * my_pointer;
The function is as follows:
const myclass& myfunc() const
{
//I have a boost shared_ptr here;
// but I have to return "const myclass &"
}
How to do that?
?
* is pronounced "dereference"...
will code like this cause a problem
const myclass& myfunc() const
{
boost::shared_ptr<myclassmy_pointer (new myclass());
return *my_pointer;
}
will the newsed object be destroyed as the shared_ptr
goes out of scope? If not when does it get destroyed?
Yes, the destructor of the shared pointer will delete the object. Then its
former address will convert to a reference. At some point - possibly the
conversion - Undefined Behavior will begin. And then when whoever collects the
reference uses it, Undefined Behavior will continue.
Why are you trying to do this? myfunc should just return a shared_ptr...
--
Phlip