On Thursday, 23 May 2013 at 13:01:25 UTC, Don wrote:
I don't think it's legal in C++:
struct S
{
const int x = 5;
};
w.cpp:4:17: error: ISO C++ forbids initialization of member ‘x’
[-fpermissive]
That is legal C++11 code. The non-static data member initializer
(=5) simply adds an implicit entry (if not present) for that
particular data member to each constructor initialization list.
Thus, the struct S above is the same as:
struct S
{
const int x;
S() : x (5) { }
};
The fact that the field is const doesn't play any significant
role here.