#include #include using std::cout; using std::endl; using std::shared_ptr; struct MyInt{ MyInt(int v):val(v){ cout << " Hello: " << val << endl; } ~MyInt(){ cout << " Good Bye: " << val << endl; } int val; }; int main(){ cout << endl; shared_ptr sharPtr(new MyInt(1998)); cout << " My value: " << sharPtr->val << endl; cout << "sharedPtr.use_count(): " << sharPtr.use_count() << endl; { shared_ptr locSharPtr(sharPtr); cout << "locSharPtr.use_count(): " << locSharPtr.use_count() << endl; } cout << "sharPtr.use_count(): "<< sharPtr.use_count() << endl; shared_ptr globSharPtr= sharPtr; cout << "sharPtr.use_count(): "<< sharPtr.use_count() << endl; globSharPtr.reset(); cout << "sharPtr.use_count(): "<< sharPtr.use_count() << endl; sharPtr= shared_ptr(new MyInt(2011)); cout << endl; }