A reference can not be NULL or it can be NULL?

后端 未结 7 930
忘了有多久
忘了有多久 2020-12-13 16:03

I have read from the Wikipedia that:

“References cannot be null, whereas pointers can; every reference refers to some object, although it may or may n

相关标签:
7条回答
  • 2020-12-13 16:52

    clang 3.5 even warns on a possible later NULL check of a reference:

    /tmp/person.C:11:6: warning: reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to
          always convert to true [-Wundefined-bool-conversion]
    if (&object1) {}
    ~~   ^~~~~~~
    1 warning generated.
    
    0 讨论(0)
提交回复
热议问题