C++ Tutorial - More On Classes - Member Initializers
I'm a little confused with the examples on two of the pages here. This is the example given on the Second Page, which looks like it belongs in the Header file. class MyClass { public: MyClass(int a, int b) : regVar(a), constVar(b) { } private: int regVar; const int constVar; }; ----------------------------------------------------------------- Then on the Third Page, the example given is: MyClass.h class MyClass { public: MyClass(int a, int b); private: int regVar; const int constVar; }; ----------------------------------------------------------------- MyClass.cpp MyClass::MyClass(int a, int b) : regVar(a), constVar(b) { cout << regVar << endl; cout << constVar << endl; } Why has the " :regVar(a), constVar(b)" seemingly moved? In case anyone needs a link to the full pages: https://www.sololearn.com/Play/CPlusPlus/