C++: Why can't data members of a class be initialized at the time of declaration as given in the following code?
Why can't data members of a class be initialized at the time of declaration as given in the following code?
class emp
{
private :
int j = 10 ;
} ;
Memory for data members of a class is allocated only when object of that class is created. One cannot store data in a memory location which does not exist at all. Therefore initialization at the time of declaration is not possible.




Comments
Log in or create a user account to comment.