When do class members get their default values in c++11? Is the following code legitimate?
class C {
void* buffer;
uint16_t& crc = *reinterpret_cast <uint16_t*> (buffer);
public:
explicit C (void* p) : buffer (p) {}
};
I expect, that the default value of crc is just syntax sugar, so that crc is initialized after buffer has been. Am I correct?
The order of initialization of non-static data members is specified in paragraph 10 of 12.6.2 Initializing bases and members [class.base.init]
(emphasis mine):
As you can see, whether the members are initialized with a so called mem-initializer (i.e. inside a constructor, before its body) or a brace-or-equal-initializer (i.e. in the class definition) or with nothing at all has no bearing on initialization order.