I am trying to overload the <= operator but the program has an error
Process finished with exit code -1073741571 (0xC00000FD)
op.h
bool operator<=(const Date& d1, const Date& d2)
{
return d1 <= d2;
}
main.cpp
cout << "Checking <=" << endl;
assert(Date(1,1,2000) <= Date(2,1,2000));
assert(!(Date(2,1,2000) <= Date(1,1,2000)));
assert(Date(2,1,2000) <= Date(1,2,2000));
assert(Date(2,2,2000) <= Date(1,1,2001));
cout << "Checking <= Complete!" << endl;
What is happening here?
In your case, you call the
bool operator<=(const Date& d1, const Date& d2)
indefinitely, wich goes out the stack eventually, because it is a recursion call. Try to compare directly the content of both your objects passed as parameters.
User contributions licensed under CC BY-SA 3.0