titanandrews
Programmer
Hi All,
A function that returns a local object is considered undefined. But why does it seem that returning a shared_ptr is ok? Even the boost examples have this:
shared_ptr<X> createX()
{
shared_ptr<X> px(new X_impl);
return px;
}
I have never run into a case where this does not work, but I just don't know why. Does anyone have an explanation?
many thanks!
A function that returns a local object is considered undefined. But why does it seem that returning a shared_ptr is ok? Even the boost examples have this:
shared_ptr<X> createX()
{
shared_ptr<X> px(new X_impl);
return px;
}
I have never run into a case where this does not work, but I just don't know why. Does anyone have an explanation?
many thanks!