Hello, why does operator overload <?

#include <iostream> #include <conio.h> using namespace std; class Date { int kurs; float rate, avarage; public: Date(int m, float d, float y) { kurs = m; rate = d; avarage = y; } bool operator < (Date &v1) { int vTemp1 = v1.kurs; return vTemp1; } ~Date(){} }; int main() { Date dt(35, 116, 92); Date dt1(70, 69, 92); bool k = dt1<dt; if(k) cout << "dt < dt1"; else cout << "dt > dt1"; getch(); return 0; } 

Closed due to the fact that off-topic participants Abyx , ߊߚߤߘ , Sergey Gornostaev , Nick Volynkin 6 Oct '17 at 4:29 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - ߊߚߤߘ, Nick Volynkin
  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Abyx, Sergey Gornostaev
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Well, you have it written in such a way that whatever you compare, the kurs of what is to the right of the comparison, reduced to bool , is displayed true ...

    If you want to, say, compare across the kurs field, write

     bool operator < (const Date &v1) const { return kurs < v1.kurs; }