Advertisement
TechOPGOHIL

Untitled

Dec 3rd, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. //write a program to unary operator overload with class function
  2. #include<iostream.h>
  3. #include<conio.h>
  4. class demo
  5. {
  6.     int a,b;
  7.     public:
  8.     demo()
  9.     {
  10.         a=10;
  11.         b=-20;
  12.     }
  13.     void operator -()
  14.     {
  15.         a=-a;
  16.         b=-b;
  17.     }
  18.     void display()
  19.     {
  20.         cout<<"\nA ="<<a<<endl;
  21.         cout<<"\nB ="<<b<<endl;
  22.     }
  23. };
  24. void main()
  25. {
  26.     clrscr();
  27.     demo d; // d is a object if you know this allredy then excelent.
  28.     d.display();
  29.     -d; // operator overload finding - sign operator in above void main.
  30.     cout<<"\nOperator Overload Sucessfully... check below\n";
  31.     d.display();
  32.     getch();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement