0

When using in-class initializers, why can I use the copy form of initialization '=' and the braced list form of initialization '{}' but no direct form '()'.

class foo{
    int a = 5;
    int b{5};
    int c(5);
};

Error: expected a type specifier

Error: syntax error: 'constant'

1 Answers1

0

I guess that won't be parsed as variable but it'll be parsed as a declaration of function .That's why it doesn't let u write 5 there .As it is expecting no argument or normal or default type of argument there . And as error also suggests that it is expecting a type specified like int or anything for 5 .And another error suggests that you can not direct pass constant there in the function . It is a syntax error .

Abhishek Panjabi
  • 439
  • 4
  • 23