//Program - 5 overload unary -- (minus minus) operator using friend function.
#include <iostream.h>
#include <conio.h>
class test
{
int a, b;
public:
test() //default constructor
{
cout << "Enter value for A = ";
cin >> a;
cout << "Enter vslue for B = ";
cin >> b;
}
void show()
{
cout << endl << "A = " << a;
cout << endl << "B = " << b;
}
friend void operator -- (test &)
};
void operator -- (test &ref)
{
-- ref.a;
-- ref.b;
}
void main()
{
clrscr();
test obj; //calls Default Constructo
--obj; //call opertor --() friend function
obj.show();
getch();
}
Comments
Post a Comment