May someone please explain why does the current vector has to be emptied in the example below (in the while loop)? What happens if the current vector is already empty? May you also give a simple example of how you would use the overloaded operator? This is under a coplien form.
Thanks for clearing those things up.
Type& Type::operator =(const Type& p_vector2)
{
if (this != &p_vector2)
{
int i = 0;
int j = vector1.size();
while (i < j)
{
delete vector1[0];
this->vector1.erase(vector1.begin());
i++;
}
for (unsigned int i=0; i < p_vector2.vector1.size(); i++)
{
this->vector1.push_back(vector2.vector1[i][0].clone());
}
}
return *this;
}