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