#include <iostream>
#include <memory>
using namespace std;
int main()
{
auto_ptr<int> p(new int(42));
auto_ptr<int> q;
cout << "after initialization:" << endl;
cout << " p: " << (p.get() ? *p : 0) << endl;
cout << " q: " << (q.get() ? *q : 0) << endl;
q = p;
cout << "after assigning auto pointers:" << endl;
cout << " p: " << (p.get() ? *p : 0) << endl;
cout << " q: " << (q.get() ? *q : 0) << endl;
*q += 13; // change value of the object q owns
p = q;
cout << "after change and reassignment:" << endl;
cout << " p: " << (p.get() ? *p : 0) << endl;
cout << " q: " << (q.get() ? *q : 0) << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewogICAgYXV0b19wdHI8aW50PiBwKG5ldyBpbnQoNDIpKTsKICAgIGF1dG9fcHRyPGludD4gcTsKCiAgICBjb3V0IDw8ICJhZnRlciBpbml0aWFsaXphdGlvbjoiIDw8IGVuZGw7CiAgICBjb3V0IDw8ICIgcDogIiA8PCAocC5nZXQoKSA/ICpwIDogMCkgPDwgZW5kbDsKICAgIGNvdXQgPDwgIiBxOiAiIDw8IChxLmdldCgpID8gKnEgOiAwKSA8PCBlbmRsOwoKICAgIHEgPSBwOwogICAgY291dCA8PCAiYWZ0ZXIgYXNzaWduaW5nIGF1dG8gcG9pbnRlcnM6IiA8PCBlbmRsOwogICAgY291dCA8PCAiIHA6ICIgPDwgKHAuZ2V0KCkgPyAqcCA6IDApIDw8IGVuZGw7CiAgICBjb3V0IDw8ICIgcTogIiA8PCAocS5nZXQoKSA/ICpxIDogMCkgPDwgZW5kbDsKCiAgICAqcSArPSAxMzsgIC8vIGNoYW5nZSB2YWx1ZSBvZiB0aGUgb2JqZWN0IHEgb3ducwogICAgcCA9IHE7CiAgICBjb3V0IDw8ICJhZnRlciBjaGFuZ2UgYW5kIHJlYXNzaWdubWVudDoiIDw8IGVuZGw7CiAgICBjb3V0IDw8ICIgcDogIiA8PCAocC5nZXQoKSA/ICpwIDogMCkgPDwgZW5kbDsKICAgIGNvdXQgPDwgIiBxOiAiIDw8IChxLmdldCgpID8gKnEgOiAwKSA8PCBlbmRsOwp9