Nesting-of-member-function in C++ .

In this session i have discussed nesting of member function in C++ .


The memeber function called with in another member function . It is called nesting of member function .


Example : Write a program that demonstrate the nesting of memeber function .

    #include<iostream>
    using namespace std;  
    class ABC
    {
       int x,y;
       public :
       void input()
       {
            cout<<"Enter the first value";
            cin>>x;
            cout<<"Enter the second value";
            cin>>y;
       }
       int max()
       {
            if(x>=y)
            {
                return(x);
            }
            else
            {
                return(y);
            }
            
       }
       void show()
       {
            cout<<"Max value : "<<max();
       }
    };
    int main()
    {
        ABC obj;  //object created
        obj.input(); 
        obj.show();
        return 0;
    }
OUTPUT : Enter the first value : 20
         Enter the second value : 10
         Max value : 20

Welcome to AndroidATPoint.

back image                     next image