Just a quick question to anyone who has used shared_ptr before. I just tried using TR1's implementation of shared_ptr (I don't know if this applies to boost), but to my frustration, I found no Detach function, to get the pointer without destroying the pointer.
I also found this resource when googling for it:
http://www.archivum.info/comp.std.c+.../msg00043.html
It specifically says shared_ptr lacks detach and is dangerous:
Is there any truth to this claim? It seems like, if true, C++ truly lacks a good smart pointer in this case and it should be best to stick to custom ones or perhaps the one in boost is better?I think this simulates new/delete semantics with a dangling pointer
check. Yes, it is not pretty, and shared_ptr does not have a detach().
But worse, it does not work (just like plain new/delete does not) in
the case of two objects A and B, where, if one is destroyed, it should
destroy the other with it. If both in their destructors call destroy,
and one of the objects gets destroyed from the outside, infinite
recursion occurs: A dtor runs -> destroys reference to B -> B dtor runs
-> destroys reference to A -> ...