Nesting of Member Function in C++

Whenever we call a member function inside another member function of one class it is known as Nesting of the member function. Generally, the member function which is called by another member function is kept private so that it cannot be called directly using the dot operator.

Let’s look at the example code below for better understanding:

Output:

Please Enter the Phone number: 9876543210

Your entered number is: 9876543210

In the above code, the nested member function is check_num(). It checks whether the given number is correct or not. Since we don’t want the user to use it directly by writing obj.check_num() so we have kept it private.

Leave a Comment

Your email address will not be published.