中易网

看看这段代码,怎么会提示date未定义啊??大神们??求解释

答案:2  悬赏:70  
解决时间 2021-03-09 03:25




最佳答案
new 后面的首字母大写。
全部回答
#include using namespace std; int days_in_month[] = {31 ,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; class date { int year, month, day; int getday(int y, int m) const { if(m!=2) return days_in_month[m]; else if(y%400==0|| (y%4==0 && y%100!=0)) return 29; else return 28; } public: date() : year(1900), month(1), day(1) {} date(int y, int m, int d) : year(y), month(m), day(d) {} date(const date& b) : year(b.year), month(b.month), day(b.day) {} date operator+(int days) { date temp = *this; if(days==0) return temp; else if(days<0) return operator-(-days); temp.day += days; while(temp.day > getday(temp.year,temp.month)) { temp.day -= getday(temp.year,temp.month); temp.month++; if(temp.month>12) { temp.month = 1; temp.year++; } } return temp; } date operator-(int days) { date temp = *this; if(days==0) return temp; else if(days<0) return operator+(-days); temp.day -= days; while(temp.day <= 0) { temp.day += getday(temp.year,temp.month-1); temp.month--; if(temp.month<=0) { temp.month = 12; temp.year--; } } return temp; } bool operator<(const date& b) const { if(year < b.year) return true; if(year == b.year && month < b.month) return true; if(year == b.year && month == b.month && day < b.day) return true; return false; } bool operator>(const date& b) const { return b<(*this); } bool operator==(const date& b) const { return !((*this)b) return -b.operator-(*this); date temp = *this; int c = 365; int ans = 0; while(temp
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯