3 ms·
In c++ if you pass something as reference there is nothing preventing the receiving function from keeping a pointer to that reference even after returning. Rig
by Too 11y ago
In c++ if you pass something as reference there is nothing preventing the receiving function from keeping a pointer to that reference even after returning.
Right now the only way to enforce this is by convention: 1. move/unique/shared_ptr=receiver allowed to keep pointer, 2. raw ptr=totally banned, 3. reference=caller must outlive callee and called function is not allowed to keep pointer after returning. The last scenario here is not enforcable by the compiler.