Advertisement
TheSadRoot

9

Jan 21st, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. class cObject {
  3. private:
  4.     int id;
  5.     double weight;
  6.  
  7. public:
  8.     cObject(int id, double w): id { id },
  9.         weight { w } { }
  10.  
  11.     void print() {
  12.         std::cout << "Object #" << id << " has weight " << weight << "\n";
  13.     }
  14.  
  15.     cObject operator--() {
  16.         return cObject(id, weight - 1.0);
  17.     }
  18.  
  19.     cObject operator--(int) {
  20.         cObject o(id, weight);
  21.         weight -= 1.0;
  22.         return o;
  23.     }
  24. };
  25.  
  26. int main() {
  27.     cObject a(1, 8);
  28.     cObject b(2, 2);
  29.  
  30.     a.print();
  31.     b.print();
  32.  
  33.     (a--).print();
  34.     (--b).print();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement