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

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

    You can think of a reference as a de-referenced pointer. Syntactically you treat a reference as though it is not a pointer: you do not need the * operator to dereference it, and you can use . rather than -> to access its members.

    However, you cannot dereference a void pointer. As pointed out by Binary Worrier trying to do that will give you a compiler error. And if you cannot have a dereferenced void pointer, that means you cannot have a void reference.

提交回复
热议问题