- made RefCountedPtr follow rule of five

This commit is contained in:
alexey.lysiuk 2021-08-03 09:52:30 +03:00 committed by Christoph Oelckers
parent 67e7d1a6f5
commit bbcd522052

View file

@ -32,9 +32,19 @@ public:
if (ptr) ptr->IncRef();
}
RefCountedPtr(const RefCountedPtr& r) : ptr(r.ptr)
{
if (ptr) ptr->IncRef();
}
RefCountedPtr(RefCountedPtr&& r) : ptr(r.ptr)
{
r.ptr = nullptr;
}
RefCountedPtr & operator=(const RefCountedPtr& r)
{
if (ptr != r.ptr)
if (this != &r)
{
if (ptr) ptr->DecRef();
ptr = r.ptr;
@ -54,11 +64,14 @@ public:
return *this;
}
RefCountedPtr & operator=(const RefCountedPtr&& r)
RefCountedPtr & operator=(RefCountedPtr&& r)
{
if (this != &r)
{
if (ptr) ptr->DecRef();
ptr = r.ptr;
r.ptr = nullptr;
}
return *this;
}