fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. class Unko
  6. {
  7. private:
  8. T* pointer;
  9. public:
  10. Unko(T* t) { pointer = t; }
  11. ~Unko() {
  12. delete(pointer);
  13. cout << "Poo!" << endl;
  14. }
  15. operator T* () const { return pointer; }
  16. T* operator -> () const { return pointer; }
  17. };
  18.  
  19. class Value
  20. {
  21. private:
  22. int value;
  23. public:
  24. Value(int v) : value(v) {}
  25. ~Value() { cout << "Oh! God!" << endl; }
  26. int getValue() { return value; }
  27. void setValue(int v) { value = v; }
  28. };
  29.  
  30. int main() {
  31. cout << "start" << endl;
  32. {
  33. Unko<int> unko(new int);
  34. *unko = 100;
  35. cout << "unko: " << *unko << endl;
  36. }
  37. {
  38. Unko<Value> val(new Value(777));
  39. cout << "value: " << val->getValue() << endl;
  40. val->setValue(999);
  41. cout << "value: " << val->getValue() << endl;
  42. }
  43. cout << "finish" << endl;
  44. return 0;
  45. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
start
unko: 100
Poo!
value: 777
value: 999
Oh! God!
Poo!
finish