Why is it impossible to have a reference-to-void?

后端 未结 10 997
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 19:32

Why is it impossible to have a reference to void? The only thing I found in the C++ Standard is this line, at 8.3.2.1

A declarator th

10条回答
  •  青春惊慌失措
    2020-12-23 20:18

    If they were, they would be semantically non-differentiated from pointers, and would amount to syntactic sugar. A reference says, "I refer to something that is of this type." Allowing void or null reference would weaken that difference from pointers.

    Granted, it's still possible for a reference to refer to an object that doesn't exist anymore, but that is an exception.

提交回复
热议问题