Nesting of Member Functions – Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

Nesting of member functionsNesting of Member Functions | Reference Notes
Object Oriented Programming (OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Nesting of Member Functions
A member function of a class can call any other member function of its own class irrespective of its privilege. This is known as nesting of member functions.

Consider the problem of finding the largest of n given number which illustrates the above concept.
#define MAX_SIZE 100
class Data
int num[MAX_SIZE];
int n;
void get_data(void);               //declaration
int largest(void);                     //declaration
void display(void);                  //declaration
void Data::get_data(void)
cout<<"Enter the total numbers(n):"<<endl;
cout<<"Enter the number:"<<endl;
for(int i=0;i<n;i++)
cout<<"Enter the number"<<i+1<<";";
int Data::largest(void)
int max;
for(int i=1;i<n;i++)
return max;
void Data::display(void)
cout<<"The largest number:"<<largest()<<endl();
void main()
Data num;

The class Data has the member function display having the statement cout<<“The largest number:”<<largest()<<endl;. It calls the member function largest() to compute the largest of n given number.

(Visited 3,423 times, 2 visits today)

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag :

Post a Comment

Your email is never published nor shared. Required fields are marked *


Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary