struct bitfield {
int i = 0; // ok
int j : 8 = 0; // error: lvalue required as left operand of assignment
};
What is the correct syntax to in
You cannot (in C++11) in-class initialize bitfields.
In MSVC and gcc (with extensions), the anonymous union and struct code lets you get around this a bit.
struct bitfield {
int i = 0; // ok
union {
uint32_t raw = 0;
struct {
int j : 8;
int x : 3;
};
};
};
where we mix a fixed size raw with a union over bitfields, then in-class initialize the raw element.