Why can't we declare a variable of type void?

后端 未结 7 1659
盖世英雄少女心
盖世英雄少女心 2020-12-08 09:43

I\'m looking for a formal explanation of that fact in the Standard. I\'ve found what 3.9.1/9 says and trying to give an explanation used that section.

S

7条回答
  •  旧时难觅i
    2020-12-08 10:27

    You cannot declare a variable of type void because variables must have object type or be references, extern void f; doesn't declare a reference, and void is not an object type:

    Section 3 [basic] says that

    A variable is introduced by the declaration of a reference other than a non-static data member or of an object.

    Section 3.9 [basic.types] says that

    An object type is a (possibly cv-qualified) type that is not a function type, not a reference type, and not a void type.

提交回复
热议问题