From 626c2cd921e7442c20ac1be7be0b9ecb44d00c95 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sat, 6 Sep 2014 22:32:49 +0100 Subject: cc examples --- c,cc/shared_ptr.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 c,cc/shared_ptr.cc (limited to 'c,cc/shared_ptr.cc') diff --git a/c,cc/shared_ptr.cc b/c,cc/shared_ptr.cc new file mode 100644 index 0000000..4fb158e --- /dev/null +++ b/c,cc/shared_ptr.cc @@ -0,0 +1,31 @@ +#include +#include + +using namespace std; + +struct B { + B(int i) : m(i) {} + int m; +}; + +struct A { + shared_ptr b; +}; + +int +main(void) +{ + shared_ptr x(new B(42)); + A* a = new A; + A* c = new A; + a->b = x; + c->b = x; + cout << x.use_count() << endl; + delete a; + cout << x.use_count() << endl; + delete c; + cout << x.use_count() << endl; + + return 0; +} + -- cgit v1.2.3