On Sunday, 11 October 2015 at 21:15:38 UTC, Jonathan M Davis
wrote:
In this case in C++, because the ref-counting is not built-in
to the type, there is no way for the Child to have access to
its parent via a shared_ptr. It has to be done via a normal
pointer. D has exactly this same problem. If the ref-counting
isn't built-in, then there are cases where you have to let a
non-ref-counted reference escape.
In this case one should use unique_ptr, so the D discussion about
ref counting is irrelevant. If you have truely shared_ptr
semantics and back pointers, then one shoud use weak_ptr for this
since the back pointers don't own the resource. Keep in mind that
shared_ptr only denote ownership, not resource usage.
C++ is now moving towards Rust and static analysis, but as a step
seperate from compilation. And that makes sense since it is time
consuming and doesn't have to be done for codegen.