summaryrefslogtreecommitdiff
path: root/c,cc/shared_ptr.cc
diff options
context:
space:
mode:
Diffstat (limited to 'c,cc/shared_ptr.cc')
-rw-r--r--c,cc/shared_ptr.cc31
1 files changed, 31 insertions, 0 deletions
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 <iostream>
+#include <memory>
+
+using namespace std;
+
+struct B {
+ B(int i) : m(i) {}
+ int m;
+};
+
+struct A {
+ shared_ptr<B> b;
+};
+
+int
+main(void)
+{
+ shared_ptr<B> 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;
+}
+