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

后端 未结 10 944
爱一瞬间的悲伤
爱一瞬间的悲伤 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

    Technically speaking, all that is guaranteed is that a reference to an object is an alias for it. That under the hood reference argument passing is done with pointers is an implementation detail. This can be confusing because of references reusing the & operator which is also address-of, but keep in mind that the operator actually has different meanings in different contexts (in a variable or parameter declaration it denotes a reference type, otherwise it's address-of, except when it's bitwise-and). Because it's technically just an alias for an object, a reference is 'always dereferenced' as Worrier explained.

提交回复
热议问题