Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //write a program to unary operator overload with friend function
- #include<iostream.h>
- #include<conio.h>
- class demo
- {
- int a,b;
- public:
- demo()
- {
- a=10;
- b=-20;
- }
- friend void operator -(demo &object) // Changes Are here
- {
- object.a=-object.a;
- object.b=-object.b;
- } // Changes Done Replace Friend In Above Void And Create Object
- void display()
- {
- cout<<"\nA ="<<a<<endl;
- cout<<"\nB ="<<b<<endl;
- }
- };
- void main()
- {
- clrscr();
- demo object; // object is a object if you know this allredy then excelent.
- object.display();
- -object; // operator overload finding - sign operator in above void main.
- cout<<"\nOperator Overload Sucessfully Using Friend Function... check below\n";
- object.display();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement