Also, is it necessary to have that setdate member function?
There will be times when you'll want to change an existing date, right? That's what it's there for, plus:
why not let the Date constructor do it?
Because the Date constructor is called BEFORE you can manipulate it! That's just a weird quirk that will make more sense in the future. To sum it up, look at this:
Date day;
int main() //...'day' constructor occurs here!!
{
day(10, 5, 99); //...too late!...'day' constuctor already called!
return 0;
}
Likewise, when you have a class nested in another class, the contructor is invoked before you even reach the larger classes constructor! This is just the way it is, but as I said, you'll usually need a "SetDate()" type function in classes anyway, so why worry?
Incidentally, a lot of professional programmers call the "Set()" function within the constructor! So instead of seeing:
Code:
Date(int _day = 0, int _month = 0, int _year = 0): day(_day), month(_month), year(_year){}
You'll see:
Code:
Date(int _day = 0, int _month = 0, int _year = 0){ SetDate(_day, _month, _year); } //...!
Well I hope I didn't confuse things!