upsidedown

operater ovrld unary r.i.p

Mar 9th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream.h>
  2.  
  3. class ovrld
  4. {
  5. public:
  6.     int x;
  7.     void display();
  8.     void operator-()
  9.     {
  10.         x=-x;
  11.     }
  12. };
  13.  
  14. void ovrld::display()
  15. {
  16.     cout<<"the integer value is:\n"<<x<<endl;
  17. }
  18.  
  19. int main()
  20. {
  21.     ovrld s;
  22.     cout<<"enter a integer value to negate it\n";
  23.     cin>>s.x;
  24.     cout<<"value before negation is:\n";
  25.     s.display();
  26.     -s;
  27.     cout<<"value after negation is:\n";
  28.     s.display();
  29.     return 0;
  30. }
  31.  
  32. OUTPUT:
  33. enter a integer value to negate it
  34. 3
  35. value before negation is:
  36. the integer value is:
  37. 3
  38. value after negation is:
  39. the integer value is:
  40. -3
  41. Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment