]> git.saurik.com Git - wxWidgets.git/commitdiff
implement explicit copying instead of forbidding it
authorGilles Depeyrot <gilles_depeyrot@mac.com>
Thu, 9 May 2002 12:18:54 +0000 (12:18 +0000)
committerGilles Depeyrot <gilles_depeyrot@mac.com>
Thu, 9 May 2002 12:18:54 +0000 (12:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15461 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/object.h
src/common/object.cpp

index 289263764593b448c24675dab63a15dabe650d1c..6f5c68ce8723df78dfb64ee013ea038a26532c4c 100644 (file)
@@ -411,12 +411,29 @@ inline void wxCheckCast(void *ptr)
 class WXDLLEXPORT wxObject
 {
     DECLARE_ABSTRACT_CLASS(wxObject)
-    DECLARE_NO_COPY_CLASS(wxObject)
 
+private:
+    void InitFrom(const wxObject& other);
+    
 public:
     wxObject() { m_refData = NULL; }
     virtual ~wxObject() { UnRef(); }
     
+    wxObject(const wxObject& other)
+        {
+            InitFrom(other);
+        }
+    
+    wxObject& operator=(const wxObject& other)
+    {
+        if ( this != &other )
+        {
+            UnRef();
+            InitFrom(other);
+        }
+        return *this;
+    }
+
     bool IsKindOf(wxClassInfo *info) const;
 
 
index b3b09abf9252da9cf13a028e200a149e29bafe02..7148e579b3d60835cdd18d08bec5ce46e2c89ca0 100644 (file)
@@ -82,7 +82,6 @@ void wxObject::Dump(wxSTD ostream& str)
 #endif
 
 
-
 #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
 void *wxObject::operator new ( size_t size, const wxChar *fileName, int lineNum )
 {
@@ -247,9 +246,18 @@ wxObject *wxCreateDynamicObject(const wxChar *name)
 
 
 // ----------------------------------------------------------------------------
-// wxClassInfo
+// wxObject
 // ----------------------------------------------------------------------------
 
+// Initialize ref data from another object (needed for copy constructor and
+// assignment operator)
+void wxObject::InitFrom(const wxObject& other)
+{
+    m_refData = other.m_refData;
+    if ( m_refData )
+        m_refData->m_count++;
+}
+
 void wxObject::Ref(const wxObject& clone)
 {
 #if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT