Private Member Function in C++

Like data member of the class a member function can also be declared as private so that it can not be accessed outside the class.
If we declare private member function then it can not be accessed directly using the object of the class so we have to access it from the public member function of the same class.

class Circle
int r;
float area ();
void getRadius ();
void DisplayArea ();
int Circle ::area ()
return (3.14 * r * r);
void Circle :: getRadius ()
cout<<"Enter Radius";
void Circle ::DisplayArea ()
Cout<<"Area="<<area ();
int main()
Circle C1;
C1.DisplayArea ();
return 0;


In the above example we have declared three member function getRadius (), DisplayArea () and area (). In which area () is defined as private.
We have called only two member functions getRadius () and DisplayArea () using the name of the object inside main function.
We have called the third member function area () from inside the DisplayArea () member function. This concept is known as private member function.

Download Projects

Download Programs