2 ms·
> now you have to add a check for null inside your function While I generally agree that non-const references make more sense for out-parameters (although I ac
by flohofwoe 5y ago
> now you have to add a check for null inside your function
While I generally agree that non-const references make more sense for out-parameters (although I actually prefer return values), don't forget that it's possible for a reference to become "null" too. It's quite unlikely to happen, but if it happens it's much worse to debug than a null pointer.
Oversimplified example:
const int& bla = *((int*)nullptr);
- mastax 5y agoDereferencing a null pointer is Undefined Behavior.