X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b5dbe15d0bacde245539f54c4d97af6b4696f01f..dd9f8b6bb6935360a8271dc3e8749fb026b601a8:/include/wx/object.h?ds=sidebyside diff --git a/include/wx/object.h b/include/wx/object.h index e24fc89e1c..88297d21b8 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -456,7 +456,26 @@ public: } T *get() const { return m_ptr; } - T *operator->() const { return get(); } + + // test for pointer validity: defining conversion to unspecified_bool_type + // and not more obvious bool to avoid implicit conversions to integer types + typedef T *(wxObjectDataPtr::*unspecified_bool_type)() const; + operator unspecified_bool_type() const + { + return m_ptr ? &wxObjectDataPtr::get : NULL; + } + + T& operator*() const + { + wxASSERT(m_ptr != NULL); + return *(m_ptr); + } + + T *operator->() const + { + wxASSERT(m_ptr != NULL); + return get(); + } void reset(T *ptr) { @@ -480,8 +499,6 @@ public: if (m_ptr) m_ptr->DecRef(); m_ptr = ptr; - if (m_ptr) - m_ptr->IncRef(); return *this; }