//Program - 2 : Overload Unary -(minus) operator using member function
#include <iostream.h>
#include <conio.h>
class Number
{
int a;
public :
Number()
{
cout << "Enter value a = ";
cin >> a;
}
void show()
{
cout << endl << " A = "<< a;
}
void operator-()
{
a = - a;
}
};
void main()
{
clrscr();
Number obj; // calls Default constructor
obj.show();
-obj; //calls operator-() function
obj.show();
getch();
}
Comments
Post a Comment