In the fallowing assignment operator I'm deleting a dynamically allocated data member of the Class I'm in. I accidentally left the "delete" in when turning the code in, but it still seems to work completely fine. What exactly is happening when I call delete and how is the swap function still working if I'm deleting m_itemArray before assigning it to temp in the Swap function?
Assignment operator:
Set& Set::operator=(const Set& rhs)
{
if (this != &rhs)
{
delete[] m_itemArray;
Set temp(rhs);
swap(temp);
}
return *this;
}
Swap Function:
void Set::swap(Set& other)
{
ItemType * temp = m_itemArray;
m_itemArray = other.m_itemArray;
other.m_itemArray = temp;
}
The way I'm thinking it works right now, is I'm letting the computer access the memory m_itemArray is using, but I'm getting lucky because the computer is not editing whatever is stored in that memory space by the time I'm accessing the Swap function.