In the copy and constructor are assigments of the member pointer, which contains the raw pointer. But these arent not only pointers, but also allocated memory which
must get handled seperatly.
I would judge them a
wrong, by not making a deep copy
but deleting the right side.
My implementation
Auto_ptr2(const Auto_ptr2 &p)
{
m_ptr= MakeCopy( p.m_ptr ); }
Auto_ptr2 operator=(const Auto_ptr2 &p)
{
if(&p==this){return *this;}
else{
delete m_ptr; m_ptr=MakeCopy( p.m_ptr );
return *this;
}
}
Another solution can be the so called
reference counting architecture, when a counter is used to controls the lifecycle of the raw pointer data.