I have a date class like below which I use to find the resultant date after adding/subtracting a few days. The constructor validates the input date and throws an exception if invalid.
class date
{
private:
int day;
int month;
int year;
bool isValid(date& d);
public:
date(); //default to starting of say Gregorian calendar
date(string strDate); // takes DD/MM/YYYY format string to initialize day, month and year
//static date today;
int operator- (date& d); //difference of two dates in no. of days
int operator- (int days); //get the date a few days before this date
void operator+ (int days); //get the date a few days after this date
};
In addition to the above I also want to keep track of today's date as part of the class itself which other parts of the program can use for calculation purposes.
Is it possible to have a static member as written in the commented line above and have the class itself initialize the object?
If yes how do we initialize the object? If no then what is the correct way of dealing with the "today" object?
I read other posts but all posts seem to deal with static members of basic types. However here multiple statements has to executed in order to get system date and hence I am thinking it is different from the other posts.