//Program - 1 overload unary operator using member function program - 1
#include <iostream.h>
#include <conio.h>
class Number
{
int a, b;
public :
Number() //Deafualt Constructor
{
cout << " Enter value of a : ";
cin >> a;
cout << " Enter value of b : ";
cin >> b;
}
void display()
{
cout << endl << "A = " << a;
cout << endl << "B = " << b;
}
void operator++()
{
++a;
++b;
}
};
void main()
{
clrscr();
Number obj; //calls Deafault constructor
obj.display();
++obj; //calls operator++() function
cout << endl << "After ++obj : ";
obj.display();
getch();
}
Comments
Post a Comment