The member functions are created and placed in the memory space only once when they are defined as a part of a class specification. Since· all the objects belonging to that class use the same member functions, no separate space is allocated for member functions when the objects are created. For each object, memory is allocated only for member data. Separate memory locations for the objects are essential since the member variables hold different data values for different objects.
Employee is a class which contains name, age and salary as member data doctor, nurse, worker are three objects of type employee. For each object, memory is allocated only for member data. However, member functions of each object share a common memory area.
cout<<"Enter name :";
cout<<"Enter age :";
cout<<"Enter salary: ";
cout<<"Name : "<<name<<endl;
cout<<" age : "<<age<<endl;
cout<<"salary : "<<salary<<endl;
cout <<"enter doctor details"<<endl;
cout <<"enter nurse details"<<endl;
cout <<"enter worker details"<<endl;
cout <<"Doctor details"<<endl;
cout <<"Nurse details"«endl;
cout <<"Worker details"«endl;