initializing class member variable during declaration

Been through 8 chapters and this following statement isnt clear:::

"initializing class member variable during declaration is not permitted"

ok great, but why???? Doesn't say why it isnt perimitted.

Any input would be appreciated. Thanks.

P.S. Im really tired. I feel like i have sand in my eyes. Was C++ this difficult for everyone starting out??? Or am I just not doing something.

ok great, but why???? Doesn't say why it isnt perimitted.


Supposedly because that's something that is to be done by the constructor.

Although really there isn't much reason for it, other than the language just [currently] doesn't allow it. It is allowed in C++0x, though.
You can't do this because in a theory class is a set of objects. Assigning attributes (chosing a condition) equals to chosing one of the elements of set. If you want to initialize attribute in the declaration it means, you don't actualy need this variable. And if you want to make an attribute with an initial value you should use constructor. Because class it's an instrumet of solving problems of the same type. Try to read theory of programming.
You can't do that because you have to let the person using your class choose which constructor they want to use - the default one, the copy constructor, one of your other constructors, etc.
Topic archived. No new replies allowed.