when a class is defined the compiler will not allocate memory.
This is true only for data member not for member function. As soon as the member function is defined the required memory for that member function is allocated. The memory for data member (variable) is allocated only when the object is constructed from the class.
class item
{ int number; float cost; public:
void getdata(int a, float b);
void putdata(void);
};
In the class item the memory is allocated for getdata and putdata member functions.
Memory is not allocated for number and cost data members.
item p; Now the memory is allocated for data member number and cost. The memory is allocated for each instances of object.
item p,q,r,s; The memory is allocated for data members of object p,q,r,and s separately for the member function only one memory location which is allocated in the definition.