Why is initialization of integer member variable (which is not const static) not allowed in C++? -


my c++ compiler complains when try initialize int member variable in class definition. tells "only static const integral data members can initialized within class". can please explain rationale behind restriction (if possible example).

the rationale "low-level" nature of c++. if allow this, compiler need generate initialization code constructors not entirely clear developer.

after might necessary initialize members of base classes on construction of derived class when base class constructors not explicitly invoked.

static const integral variables not need intitalization upon object creation.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -