Fix (and test) that copy constructor decrements previous object counter
This commit is contained in:
1 parent
4a1a0c8855
commit
2e30a9f407
2 files changed
+21
-4
No files matched your search
+11
-3
@@ -54,10 +54,18 @@ public:
|
||||
|
||||
rcp<T> & operator=(const rcp & other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
if (ptr)
|
||||
if (ptr != other.ptr)
|
||||
{
|
||||
ptr->rcp_inc();
|
||||
T * old_ptr = ptr;
|
||||
ptr = other.ptr;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->rcp_inc();
|
||||
}
|
||||
if (old_ptr)
|
||||
{
|
||||
old_ptr->rcp_dec();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user