On March 13, 2016 6:36:49 PM EDT, Phil Bouchard
So you have a cycle being wiped out by the proxy:
+-> a1 ---> a2 -+ | | +---------------+
1) a1.~A() will be called
2) a1.~A() will call a2.foo()
3) But a2 might have been wiped out already.
So if you try to access a member in the destructor without explicitly checking if it was destroyed already then this will lead to an undefined behavior, just like dereferencing a null pointer.
I could throw an exception when operator -> is used while a cycle is being destroyed but I don't think the overhead is worth it for this special case only.
Neither answer is great. The exception could occur during shack unwinding, so you couldn't use your pointers in very many contexts. No exception means UB, which means users have to remember a special case and thereby lose safety. I fail to see how that is better than using weak_ptr. In that case, one must always be explicit rather than remember special cases. ___ Rob (Sent from my portable computation engine)