From 82015eb61656e83eb65bae85df0aa4d7a9fadd71 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sat, 19 Apr 2014 11:11:57 +0200 Subject: [PATCH] play around with make_shared<>() --- shared_ptr.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/shared_ptr.cpp b/shared_ptr.cpp index 5d897fa..f2d28b5 100644 --- a/shared_ptr.cpp +++ b/shared_ptr.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -67,8 +68,35 @@ void weak_ptr() { } } +void add_one(std::shared_ptr i) { + (*i)++; +} + +void make_shared() { + std::cout << __FUNCTION__ << std::endl; + + std::shared_ptr sp = std::shared_ptr(new int(12)); + assert(*sp == 12); + add_one(sp); + assert(*sp == 13); + + auto sp2 = std::shared_ptr(new int(12)); + assert(*sp2 == 12); + add_one(sp2); + add_one(sp2); + add_one(sp2); + assert(*sp2 == 15); + + auto sp3 = std::make_shared(12); + assert(*sp3 == 12); + add_one(sp3); + add_one(sp3); + assert(*sp3 == 14); +} + int main() { shared_ptr(); shared_ptr_container(); weak_ptr(); + make_shared(); }