From: Thomas Geymayer Date: Mon, 2 Jun 2014 23:58:57 +0000 (+0200) Subject: SGSharedPtr: add constructor to convert from SGWeakPtr. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7d9797e091c8295693e97c7068f79f42a7f02643;p=simgear.git SGSharedPtr: add constructor to convert from SGWeakPtr. --- diff --git a/simgear/structure/SGSharedPtr.hxx b/simgear/structure/SGSharedPtr.hxx index 87497b8e..9e92a7b0 100644 --- a/simgear/structure/SGSharedPtr.hxx +++ b/simgear/structure/SGSharedPtr.hxx @@ -60,6 +60,9 @@ public: template SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get()) { get(_ptr); } + template + explicit SGSharedPtr(const SGWeakPtr& p): _ptr(0) + { reset(p.lock().get()); } ~SGSharedPtr(void) { reset(); } diff --git a/simgear/structure/shared_ptr_test.cpp b/simgear/structure/shared_ptr_test.cpp index d7b73641..877e1468 100644 --- a/simgear/structure/shared_ptr_test.cpp +++ b/simgear/structure/shared_ptr_test.cpp @@ -72,6 +72,9 @@ BOOST_AUTO_TEST_CASE( virtual_weak_ptr ) SGSharedPtr ptr1( weak_ptr.lock() ); BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 2 ); + // converting constructor + BOOST_REQUIRE_EQUAL( SGSharedPtr(weak_ptr), ptr1 ); + SGSharedPtr ptr2( weak_ptr.lock() ); BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 3 );