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.
Example
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.
#include class employee { private: char name[15]; int age; float salary; public: void getdata() { cout<<"Enter name :"; cin>>name; cout<<"Enter age :"; cin>>age; cout<<"Enter salary: "; cin>>salary; } void putdata() { cout<<"Name : "<<name<<endl; cout<<" age : "<<age<<endl; cout<<"salary : "<<salary<<endl; } }; void main() { employeedoctor,nurse,worker; cout <<"enter doctor details"<<endl; doctor.getdata(); cout <<"enter nurse details"<<endl; nurse.getdata(); cout <<"enter worker details"<<endl; worker.getdata(); cout <<"Doctor details"<<endl; doctor.putdata(); cout <<"Nurse details"«endl; nurse.putdata(); cout <<"Worker details"«endl; worker.putdata(); }