I'm trying to make the add_day function work, but I'm having some trouble. Note that I can't make any changes to the struct(it's very simplistic) because the point of the exercise is to make the program work with what's given. The code is
#include "std_lib_facilities.h"
struct Date{
int y, m, d;
Date(int y, int m, int d);
void add_day(int n);
};
void Date::add_day(int n)
{
d+=n;
}
ostream& operator<<(ostream& os, const Date& d)
{
if(d.m<1 || d.m>12 || d.d<1 || d.d>31) cout << "Invalid date: ";
return os << '(' << d.y
<< ',' << d.m
<< ',' << d.d << ')';
}
int main()
{
Date today(1978,6,25);
today.add_day(1);
cout << today << endl;
keep_window_open();
}
I'm getting a linker error that says undefined reference to Date::Date(int,int,int), but I can't figure out what's wrong. It seems like it's something to do with the Date constructor, but I'm not sure what.
I'd also like to add in a line of code for tomorrow like
Date tomorrow = today.add_day(1);
but I've got a feeling that since add_day is a void type there will be a conversion issue.
Any help would be appreciated - thanks.
P.S. Don't worry about adding days at the end of the month. It's something that's going to be implemented later.