#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;
}