In C++11 one can do
struct S {int i = 42;};
and if one forgets to initialize the member i
it
gets default initialized to 42. I Just tried this with
bitfields as
struct S {int i = 42 : 5;};
and am getting
error: expected ';' before ':' token
Does this feature exist for bitfield members and if so, how do I use it?
No, bit-fields do not allow an initializer as part of the member declaration. You can see this in the part of the grammar that describes class members (C++11 and later, [class.mem]):
The third form is the grammar for a bit-field declaration, but only the second form lists the brace-or-equal-initializer.