struct bitfield {
int i = 0; // ok
int j : 8 = 0; // error: lvalue required as left operand of assignment
};
What is the correct syntax to initialize bit-fields using C++11 "in-class initialization" feature?
What is the correct syntax to initialize bit-fields using C++11 "in-class initialization" feature?
You cannot initialize bit-fields in-class. Paragraph 9.2 of the C++11 Standard specifies the grammar for class member declarators:
[...]
member-declarator:
declarator virt-specifier-seq(opt) pure-specifier(opt)
declarator brace-or-equal-initializer(opt)
identifier(opt) attribute-specifier-seq(opt): constant-expression
As you can see, declarators for bit-field members cannot be terminated by a brace-or-equal-initializer.