3 ms·
References are absolutely modern C++. There isn't a nontrivial C++ program in existence that doesn't use references.
by pcwalton 8y ago
References are absolutely modern C++. There isn't a nontrivial C++ program in existence that doesn't use references.
- int_19h 8y agoYes, and most of those references are to locals that are passed as arguments to function calls that will never take their address. In other words, it's pass-by-ref - which is perfectly safe - not pointers. To obtain a reference to an object that is managed by a smart pointer, you would have to, at the minimum, explicitly dereference that pointer with *. In most cases, this also happens in an argument context, and the caller will maintain the pointer. It breaks when the pointer that's managing lifetime is a part of mutable state that the callee can touch somehow without returning - then it can cause the object to be freed while still holding a non-counting reference to it. At that point, you basically need something like Rust lifetime/ownership tracking to prevent such unsafe situations from happening.