How to access the Private Member Function in C++

How to access the Private Member Function in C++?

A function declared inside the private access specifier of the class, is known as a private member function. A private member function can be accessed through the only public member function of the same class.

Example:

For example, there is a class named “Student”, which has the following private data members and public member functions:

Private Data members

      • rNo is used to store the roll number of the student.
      • perc is used to store the percentage of the student.

Public Member functions

      • read() –  read()  function is used here to read roll number and percentage of the student.
      • print() – print() function is used to print roll number and percentage of the student

Here, TakeNumbersBegin () and TakeNumbersBeginFinish () are the private member functions which are calling inside public member function in the same class

Output

Input started…

Enter roll number: 5

Enter percentage: 10

Input Finish…

Roll Number: 5

Percentage: 10

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]