Hy! This is my first question on this site. Sorry for my English, if I will make mistakes:(
So, my problem is the following. I have simple class Date.
class Date
{
public:
Date();
Date(unsigned short day, unsigned short month, unsigned short year);
Date(const Date &date);
unsigned short getDay();
unsigned short getMonth();
unsigned short getYear();
void setDay(unsigned short day);
void setMonth(unsigned short month);
void setYear(unsigned short year);
void printOnScreen()const;
friend
std::ostream& operator<< (std::ostream& out, const Date& date) {
out << date.day << "." << date.month << "." << date.year;
return out;
}
friend
bool operator<(const Date& a, const Date& b) {
if (a == b) {
return false;
}
if (a.year < b.year) {
return true;
}
if (a.month < b.month) {
return true;
}
if (a.day < b.day) {
return true;
}
return false;
}
friend
Date& operator-(Date& a) {
return a;
}
friend
Date operator-(const Date& a, const Date& b) {
return Date(
abs(a.day - b.day),
abs(a.month - b.month),
abs(a.year - b.year)
);
}
friend
bool operator==(const Date& date1, const Date& date2) {
return (
date1.day == date2.day &&
date1.month == date2.month &&
date1.year == date2.year
);
}
virtual ~Date();
private:
friend KeyHasher;
unsigned short day;
unsigned short month;
unsigned short year;
};
In my main function I call sort like in this example, and after it get the error.
auto dates = {
Date(1, 5, 2016),
Date(3, 2, 2015),
Date(3, 3, 2000),
Date(2, 1, 1991),
Date(1, 8, 2200),
Date(1, 8, 2200),
Date(1, 8, 2020),
Date(21, 9, 2016)
};
vector<Date> v1(dates);
sort(
v1.begin(),
v1.end(),
less<Date>()
);
What is wrong, I don't understand. Thank you for help.
Aucun commentaire:
Enregistrer un commentaire