Hello,

I am not sure why, when I call my method, it goes into a continuous loop and prints out nothing. The operator - method is suppose to be able to subtract a Date object and a Date argument.

I will clarify if anything needs clarifying, thanks for the help

int Date::operator-(const Date& d) const
{
 Date temp(myMonth,myDay,myYear);
 Date copy = d;
 int count = 0;
  
 if(temp < copy)
{
  while (temp != copy)
  {
   temp++;
   count++;
  }
  return count * -1;
}
 else if(temp > copy)
{  
  while(temp!= copy)
  {
    temp--;
    count++;
  }
  return count;
}
if(temp == copy)
  return 0;
  
}

What is the method supposed to return? The number of seconds between two dates? If yes, remember that seconds may be large and take too long time to be computed by incrementing/decrementing temp

Member Avatar for Mouche

I don't think it's a speed issue.

I'm guessing you made this class. Do you have a working =, ==, > and < operators?

Use some print statements to see the month, day and year that you're comparing in the loops. That will help you make sure that your operators are working correctly. If they aren't, then you know what to fix.

You need to also overload the other operators you used in the above code. if you have, post the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.