INITIALISATION
| G SATISH KUMAR (16) | |||
| why cant we initialise data members of class as shown. class items{ private: int x=10; // why is this step wrong int y; }; | |||
| ropez (312) | |||
It's only possible to initialize static, integral variables like that. To get some idea about why you can't initialize non-static members in this way, consider if you have more than one constructor:
The variable
x is initialized differently depending on which constructor is called. | |||
This topic is archived - New replies not allowed.
