Nesting of Member Functions

A member function of a class can be called only by an object of that class using a dot operator. However, there is an exception to this. A member function can be called by using its name inside another member function of the same class. This is known as nesting of member functions.

Nesting of Member Function
#include
using namespace std;
class set
{
int m,n;
public:
void input(void);
void display(void);
void largest(void);
};
int set :: largest(void)
{
if(m >= n)
return(m);
else
return(n);
}
void set :: input(void)
{
cout << "Input value of m and n"<<"\n";
cin >> m>>n;
}
void set :: display(void)
{
cout << "largest value=" << largest() <<"\n";
}

int main()
{
set A;
A.input();
A.display();

return 0;
}

The output of program would be:
Input value of m and n
25 18
Largest value=25

26 comments:

  1. This is not a correct program and its showing some errors.

    ReplyDelete
  2. u have to replace void largest(void); with int largest(void);

    ReplyDelete
  3. Replies
    1. Here void input()
      void dislpay() and
      void largest() are declared in the public specifier of class 'set' instead of declaring outside
      Here they've used :: ie scope resolution operator
      This is called nesting of member function

      Delete
    2. He is calling largest() function inside the display() function, That is called nesting of member function.

      Delete
  4. He is calling largest() function inside the display() function, That is called nesting of member function. Visit for C, C++ , HTML And CSS Proejcts

    ReplyDelete
  5. thi program have some errors..!!

    ReplyDelete
  6. A member function of a class can be called only by an object of that class using a dot operator

    ReplyDelete
  7. what is the meaning of this line
    please explain me

    ReplyDelete
    Replies
    1. this means when u are calling member function or simply say that function first u need to write object name then (.) dot operator and then writing function name i.e object.function name

      Delete
  8. what is the meaning of this line
    please explain me

    ReplyDelete
  9. It's a simple function call dude,not a nesting...brush up

    ReplyDelete
  10. Its correct and perfect example of nested function, only the mistake that has been done with this program is, in it's declaration part. In function declaration function largest(),data type used as void and this has been defined with int., that is wrong. So, Function declaration should also be
    int largest();

    ReplyDelete
  11. I don't think it's a nesting of member function

    ReplyDelete
  12. Something is wrong in this program

    ReplyDelete
  13. this program has create a error

    ReplyDelete
  14. Header file not declaration correct
    And check this program

    ReplyDelete
  15. This program is working no one correctly used the program

    ReplyDelete
  16. If I'm not wrong then these is an outside the class definition and not nesting of members because in nesting of members we are using the functions inside only but anyway correct me if I wrong..

    ReplyDelete