In addition
Richard's answer. I'm going to show you how to implement the constructor and the overloading of the
<
operator. The remaining stuff is up to you.
#include <iostream>
#include <memory>
using namespace std;
class Date
{
int day, month, year;
public:
Date ( int day, int month, int year): day(day), month(month), year(year){}
friend bool operator < ( const Date & da, const Date & db);
};
bool operator < ( const Date & da, const Date & db)
{
if ( da.year == db.year)
{
if ( da.month == db.month)
{
return (da.day < db.day);
}
return ( da.month < db.month);
}
return (da.year < db.year);
}
Please note:
- You mispelled the
isValid
method name. - In the
isValid
implementation you missed to check the correctness of both the year
and the month
values.