As you can tell from the title I'm trying to build an overloaded equality operator to see when two objects are equal, however it doesn't seem to work, so I was hoping one of you fine people could point out the problem to me.
here's the code, not: m_speed, m_altitude, m_bearing, m_start are integers; m_x and m_y are floats; and m_name is a character array.
bool FlightPlan:
![Surprise [:O]](/emoticons/emotion-3.gif)
perator==(const FlightPlan &other)
{
fprintf (stderr, "Equality Operator runs to #1\n");
if (other.m_speed==m_speed && other.m_bearing==m_bearing && other.m_altitude==m_altitude && other.m_start==m_start && other.m_x==m_x && other.m_y==m_y)
{//control#1: to check Flight I.D.
fprintf (stderr, "Equality Operator runs to #2\n");
if (strlen(m_name)!=strlen(other.m_name) || m_name==0 || other.m_name==0)//if not the same length or either is NULL, not equal
return false;
fprintf (stderr, "Equality Operator runs to #3\n");
for (int i=0; strlen(m_name); i++)
if (m_name[i]!=other.m_name[i])//if unique characters exist, not equal
return false;
fprintf (stderr, "Equality Operator runs to #4\n");
return true;//if it passes all other tests then objects, equal
}//end control#1
else
return false;
}
Here's the relevant stderr output:
Equality Operator runs to #1
The program has unexpectedly finished.
Thanks,
James