Monday, 15 March 2010

c++ - Initialize private access variable -



c++ - Initialize private access variable -

inc++, valid initialize private access variable outside of class definition this?

class test { private: int a; public: int b; } int test::a = 1;

the illustration in question not valid. if fellow member variable static can initialize in example. if fellow member variable not static should initialize in in either constructor or class definition.

it not matter access privilege , variables initialized same way regardless if public, protected, or private .

struct foo { foo() : a{1} // ctor-initializer { b = 2; // ctor body } int a; int b; int c = 3; // @ definition. };

c++ class initialization private

No comments:

Post a Comment