fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Unko
  5. {
  6. private:
  7. static int counter;
  8. const int number;
  9. int value;
  10. public:
  11. Unko() : number(Unko::counter++), value(0) { }
  12. Unko(const int v) : number(Unko::counter++), value(v) { }
  13. ~Unko() { cout << "Poo! (" << number << ')' << endl; }
  14. operator int() const { return value * number; }
  15.  
  16. Unko operator + (const Unko& u1) const {
  17. return Unko(u1.value + value);
  18. }
  19. };
  20.  
  21. int Unko::counter = 1;
  22.  
  23. int main() {
  24.  
  25. Unko u1(10);
  26. Unko u2(100);
  27.  
  28. cout << u1 << endl;
  29. cout << u2 << endl;
  30. cout << u1 + u2 << endl;
  31. cout << u1 + u2 << endl;
  32. cout << u1 + u1 + u1 << endl;
  33.  
  34. // your code goes here
  35. return 0;
  36. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
10
200
330
Poo! (3)
440
Poo! (4)
180
Poo! (6)
Poo! (5)
Poo! (2)
Poo! (1)