Thursday 26 March 2015

Nesting of Member Functions

A member function of a class is accessed by the objects of that class using the dot operator. A member function of a class can call any other member function of its own class irrespective of its privilege and this situation is called nesting of member functions. The method of calling member function of one’s own class is similar to calling any other standard functions as illustrated in the following program.

Sample Program

#include <iostream.h>
Class NumberPairs
{
int num1,num2;
public:
void read()
{
cout<<”Enter the First Number”;
cin>>num1;
cout<<”Enter the second Number”;
cin>>num2;
}
int max(void)
{
if(num1 > num2)
return num1;
else
return num2;
}
void showmax(void)
{
cout<<”Maximum is “<<max();
}
};
void main()
{
NumberPairs N;
N.read();
N.showmax();
}

No comments:

Post a Comment