#include <iostream>
using namespace std;
template <class T>
class Unko
{
private:
T* pointer;
public:
Unko(T* t) { pointer = t; }
~Unko() {
delete(pointer);
cout << "Poo!" << endl;
}
operator T* () const { return pointer; }
T* operator -> () const { return pointer; }
};
class Value
{
private:
int value;
public:
Value(int v) : value(v) {}
~Value() { cout << "Oh! God!" << endl; }
int getValue() { return value; }
void setValue(int v) { value = v; }
};
int main() {
cout << "start" << endl;
{
Unko<int> unko(new int);
*unko = 100;
cout << "unko: " << *unko << endl;
}
{
Unko<Value> val(new Value(777));
cout << "value: " << val->getValue() << endl;
val->setValue(999);
cout << "value: " << val->getValue() << endl;
}
cout << "finish" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGUgPGNsYXNzIFQ+CmNsYXNzIFVua28Kewpwcml2YXRlOgoJVCogcG9pbnRlcjsKcHVibGljOgoJVW5rbyhUKiB0KSB7IHBvaW50ZXIgPSB0OyB9Cgl+VW5rbygpIHsKCQlkZWxldGUocG9pbnRlcik7CgkJY291dCA8PCAiUG9vISIgPDwgZW5kbDsKCX0KCW9wZXJhdG9yIFQqICgpIGNvbnN0IHsgcmV0dXJuIHBvaW50ZXI7IH0KCVQqIG9wZXJhdG9yIC0+ICgpIGNvbnN0IHsgcmV0dXJuIHBvaW50ZXI7IH0KfTsKCmNsYXNzIFZhbHVlCnsKcHJpdmF0ZToKCWludCB2YWx1ZTsKcHVibGljOgoJVmFsdWUoaW50IHYpIDogdmFsdWUodikge30KCX5WYWx1ZSgpIHsgY291dCA8PCAiT2ghIEdvZCEiIDw8IGVuZGw7IH0KCWludCBnZXRWYWx1ZSgpIHsgcmV0dXJuIHZhbHVlOyB9Cgl2b2lkIHNldFZhbHVlKGludCB2KSB7IHZhbHVlID0gdjsgfQp9OwoKaW50IG1haW4oKSB7Cgljb3V0IDw8ICJzdGFydCIgPDwgZW5kbDsKCXsKCQlVbmtvPGludD4gdW5rbyhuZX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