错在哪里了?怎么改正?
以下代码在dev C++中编译的时候总是提示Month Date::month() const;这个成员函数定义出错,提示是:syntax error before '::' ,这是怎么回事?谢谢!
#include <iostream>
#include <cstdlib>
using namespace std;
class Date
{
public:
enum Month{jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec};
class Bad_date{}; //exceptions
Date(int dd = 0, Month mm = Month(0), int yy = 0);
static void set_default(int, Month, int);
//function for examining the Date
int day() const;
Month month() const;
int year() const;
private:
int d, y;
int m;
static Date default_date;
bool leapyear(int yy);
};
Date::Date(int dd, Month mm, int yy)
{
if (yy == 0)
{
yy = default_date.year();
}
if (mm == 0)
{
mm = default_date.month();
}
if (dd == 0)
{
dd = default_date.day();
}
//check that the Date is valid
int max;
switch (mm)
{
case feb:
max = 28 + leapyear(yy);
break;
case apr: case jun: case sep: case nov:
max = 30;
break;
case jan: case mar: case may: case jul: case aug: case oct: case dec:
max = 31;
break;
default:
throw Bad_date();
}
if ((dd < 1 )|| (max < dd))
{
throw Bad_date();
}
y = yy;
m = mm;
d = dd;
}
Date Date::default_date(16, dec, 1770);
void Date::set_default(int d, Month m, int y)
{
Date::default_date = Date(d, m, y);
}
inline int Date::day() const
{
return d;
}
inline Month Date::month() const //总是提示该行:syntax error before '::'
{
return m;
}
inline int Date::year() const
{
return y;
}
bool Date::leapyear(int yy)
{
return false;
}
int main()
{
Date today;
system("PAUSE");
return 0;
}