I thought I had understood it. But now this site is confusing me... http://www.informit.com/articles/article.aspx?p=1852519
Class Member Initialization
C++11 pulls another rabbit out of its hat with class member initializers. Perhaps an example will best illustrate these:
class C { int x=7; //class member initializer public: C(); };
The data member x is automatically initialized to 7 in every instance of class C. In former dialects of C++, you would use the more cumbersome mem-init notation for the same purpose:
class C { int x; public: C() : x(7) {} };
(...)
Notice that a class member initializer can consist of any valid initialization expression, whether that's the traditional equal sign, a pair of parentheses, or the new brace-init:
class C { string s("abc"); double d=0; char * p {nullptr}; int y[5] {1,2,3,4}; public: C(); };
Regardless of the initialization form used, the compiler conceptually transforms every class member initializer into a corresponding mem-init. Thus, class C above is semantically equivalent to the following class:
class C2 { string s; double d; char * p; int y[5]; public: C() : s("abc"), d(0.0), p(nullptr), y{1,2,3,4} {} };
class C
{
int x=7; //class member initializer
The way I understood it, this shouldn't be a class member initializer. It should be an assignment instead....
And how can these two be similar? That's exactly what I was trying in the first place!
class C
{
string s("abc");
C() : s("abc")