A safe, non-owning C++ pointer class
Sometimes some object A needs to interact with another object B, e.g., A calls one of B’s methods. In a memory-unsafe language like C++, it is left to the programmer to assure that B outlives A; if B happens to be already destructed, this would be a use-after-free bug. Managing object lifetimes can be tricky, especially with asynchronous code. Perhaps unneeded, but here is a simple example of the problem: struct Foo { void foo (); }; struct Bar { Foo * f ; void call_foo () { f -> foo (); } };