一个错误不知道怎么改

阿川Dream 阿川Dream 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

#ifndef _DATE_H
#define _DATE_H
#include <string>
class Date
{
public:
enum Month{jan=1,feb,apr,may,jun,jul,aug,sep,oct,nov,dec};
class Bad_date{};
Date(int dd=0,Month mm=Month(0),int yy=0);
void Date::string_rep()const;//输出
static void set_default(int,Month,int);
Date& add_year(int n);
Date& add_month(int n);
Date& add_day(int n);
bool leapyear(int y);
private:
int d,m,y;
static Date default_date;
};
#endif
//date-func.cpp:
#include "date.h"
#include <ctime>
Date::Date(int dd=1,Month mm=Month(1);int yy=1970)
{
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;
default:
throw Bad_date();
}
if (dd<1||max<dd) throw Bad_date();
y=yy;
d=dd;
m=mm;
}
Date& Date::add_year(int n)
{
if (d==29&&m==2&&!=leapyear(y+n))
{
d=1;
m=3;
}
y+=n;
return *this;
}
Date& Date::add_month(int n)
{
if (n==0)return *this;
if (n>0)
{
int delta_y=n/12;
int mm=m+n%12;
if (mm>12)
{
delta_y++;
mm-=12;
}
//处理month(m)没有天数的情况
y+=delta_y;
m=Month(mm);
return *this;
}
return *this;
}
Date& Date::add_day(int n)
{
if (n==0)return *this;
if (n>0)
{
std::tm tm;
tm.tm_sec=0;
tm.tm_min=0;
tm.tm_hour=12;
tm.tm_mday=1+days;
tm.tm_mon=1;
tm.tm_year=70;
std::mktime(&tm);
d=tm.tm_mday;
m=tm.tm_mon;
y=tm.tm_year;
return *this;
}
}
static void Date::set_default(int,Month,int)
{
Date::default_date=Date(d,m,y);
}
bool Date::leapyear(int y)
{
if (y%4==0&&y%100!=0||y%400==0)
return true;
else
return false;
}
void Date::string_rep()const
{
std::cout<<d<<'\t'<<m<<'\t'<<year<<std::endl;
}
//main.cpp:
#include <iostream>
#include "date.h"
using namespace std;

int main()
{
Date ddate(1,Date::Month(1),1970);
cout<<"starting:\n";
cout<<"a.加天数 b.加月数\n";
cout<<"c.加年数 d.退出\n";
char s;
int ld,lm,ly;
while (cin>>s)
{
switch (s)
{
case 'a':
cout<<"输入要加的天数:";
cin>>ld;
ddate.add_day(ld);
ddate.string_rep();
break;
case 'b':
cout<<"输入要加的月数:";
cin>>lm;
ddate.add_month(lm);
ddate.string_rep();
break;
case 'c':
cout<<"要输入的年数:";
cin>>ly;
ddate.add_year(ly);
ddate.string_rep();
break;
case 'd':
cout<<"bye";
exit(0);
default:
break;
}
}
system("pause");
return 0;
}

要实现的功能是从 1月1日1970年,加天、月、年后的日期,函数报错
Circular date_func <- date_func.o dependency dropped.
怎么改也改不过来了,新手求帮助
...全文
评论 3
收藏 已收藏
分享
返回顶部
阿川Dream
C++ 语言 65,212 成员 250,513 内容