Allow constructing/assigning wxObjectDataPtr from compatible type
Generalize copy ctor and assignment operators to allow implicit conversions from wxObjectDataPtr<D> to wxObjectDataPtr<B> if D is implicitly convertible to B (e.g. if B is the base class and D is a class derived from it). This makes wxObjectDataPtr<> more like standard smart pointer classes and more useful.
This commit is contained in:
@@ -278,6 +278,15 @@ public:
|
||||
m_ptr->IncRef();
|
||||
}
|
||||
|
||||
// generalized copy ctor: U must be convertible to T
|
||||
template <typename U>
|
||||
wxObjectDataPtr(const wxObjectDataPtr<U> &tocopy)
|
||||
: m_ptr(tocopy.get())
|
||||
{
|
||||
if (m_ptr)
|
||||
m_ptr->IncRef();
|
||||
}
|
||||
|
||||
~wxObjectDataPtr()
|
||||
{
|
||||
if (m_ptr)
|
||||
@@ -330,6 +339,17 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
wxObjectDataPtr& operator=(const wxObjectDataPtr<U> &tocopy)
|
||||
{
|
||||
if (m_ptr)
|
||||
m_ptr->DecRef();
|
||||
m_ptr = tocopy.get();
|
||||
if (m_ptr)
|
||||
m_ptr->IncRef();
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxObjectDataPtr& operator=(T *ptr)
|
||||
{
|
||||
if (m_ptr)
|
||||
|
Reference in New Issue
Block a user