SGSharedPtr: add constructor to convert from SGWeakPtr.

This commit is contained in:
Thomas Geymayer 2014-06-03 01:58:57 +02:00
parent 67a8d8049f
commit 7d9797e091
2 changed files with 6 additions and 0 deletions

View File

@ -60,6 +60,9 @@ public:
template<typename U>
SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get())
{ get(_ptr); }
template<typename U>
explicit SGSharedPtr(const SGWeakPtr<U>& p): _ptr(0)
{ reset(p.lock().get()); }
~SGSharedPtr(void)
{ reset(); }

View File

@ -72,6 +72,9 @@ BOOST_AUTO_TEST_CASE( virtual_weak_ptr )
SGSharedPtr<Base1> ptr1( weak_ptr.lock() );
BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 2 );
// converting constructor
BOOST_REQUIRE_EQUAL( SGSharedPtr<Base1>(weak_ptr), ptr1 );
SGSharedPtr<Base2> ptr2( weak_ptr.lock() );
BOOST_REQUIRE_EQUAL( ptr.getNumRefs(), 3 );