4 ms·
No the gp is correct, references in c++ can't be null. Your code invoked undefined behavior before you did anything with a reference, namely *a which is a null
by ethan_g 8y ago
No the gp is correct, references in c++ can't be null. Your code invoked undefined behavior before you did anything with a reference, namely *a which is a null pointer dereference.
- the_why_of_y 8y ago> namely *a which is a null pointer dereference. Which is a textbook example of the null reference problem. Edit: There may be some terminological confusion here: when programming language folks talk about "references", they include in that definition what C/C++ call "pointers". See for example the Wikipedia article, which gives as the C++ example not C++ references, but C++ pointers. https://en.wikipedia.org/wiki/Reference_(computer_science) https://en.wikipedia.org/wiki/Reference_(computer_science)
- coldtea 8y ago>Your code invoked undefined behavior before you did anything with a reference Since nobody stopped you, the problem is still there.
- mdpopescu 8y agoThe "null problem" is that a static language does a run-time check instead of a compile-time check. By the time the undefined behavior is invoked, compilation ended.