0

Why doesn't void(); here result in a compilation error?

How is this interpreted by the compiler based on the standard?

class X;

int main()
{
    //void(int);    error: expected primary-expression before 'void'
    //void(void);   error: expected primary-expression before 'void'
    //void;         error: declaration does not declare anything [-fpermissive]
    //X();          error: invalid use of incomplete type 'class X'
    void(0);    // functional cast expression to void?
    void();     // ???
}
vbstb
  • 1,261
  • 1
  • 10
  • 14
  • `X();` this is actually wrong because `x` is not defined. It will be okay if you change `class X;` to `class X {};` – DimChtz May 26 '18 at 06:48
  • @DimChtz Yes I know that, I just put it there because `void` is also a incomplete type. – vbstb May 26 '18 at 06:50
  • [Difference between parsing of \`void()\` and \`int()\`](//stackoverflow.com/q/48913009) explains `void()`. – Baum mit Augen May 26 '18 at 06:52

0 Answers0