Overloading <= operator but program ends with exit code -1073741571 (0xC00000FD)

-2

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?

c++
c++11
operator-overloading
asked on Stack Overflow Nov 17, 2019 by LtMuffin

1 Answer

2

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.

answered on Stack Overflow Nov 17, 2019 by ltabis • edited Nov 17, 2019 by ltabis

User contributions licensed under CC BY-SA 3.0