#include <iostream>
#include <iomanip>
#include "Date.h" //include definition of class Date from Date.h
#include <stdexcept>
usingnamespace std;
//Date constructor(Should do rage checking)
Date::Date(int m, int d, int y)
{
setDate( month, day, year);
}//End of Constructor
void Date::setDate(int m, int d, int y)
{
month(m);
day(d);
year(y);
}
void Date::setMonth(int m)
{
if(m >= 1 && m <= 12)
month = m;
elsethrow invalid_argument("Month must be 1-12");
}
void Date::setDay(int d)
{
if(d > 0 && d <= 31)
day = d;
elsethrow invalid_argument("Days must be 1-31");
}
void Date::setYear( int y)
{
if(y >= 0)
year = y;
elsethrow invalid_argument("Year must be 0 or greater.");
}
int Date::getMonth()
{
return month;
}
int Date::getDay()
{
return day;
}
int Date::getYear()
{
return year;
}
void Date::print()
{
cout << month << '/' << day << '/' << year << endl;
}/
I am not sure why I getting the error. I took the constructor from another program that works and modified to this one but I did not change anything that would alter the behavior of the program.
I believe the data member month/day/year of the Date class are not class type, if they are int type, you cannot init them in that way except in Date constructor's initialization list. So use assignment to fix the error.