编译中出现的错误,大家帮忙看看,谢谢

napoleonpan 2006-03-24 11:16:52
//如果是闰年,打印年月日
#include <iostream>
#include <iomanip>
using namespace std;

class Date
{
private:
int year, month, day;
public:
void set(int y, int m, int d);
bool isLeapYear() const;
void print() const;
};

inline void Date::set(int y, int m, int d)
{
year=y, month=m, day=d;
}

inline bool Date::isLeapYear()
{
return ( (year%4==0 && year%100!=0) || year%400==0 );
}

inline void Date::print()
{
cout << setfill('0');
cout << setw(4) << year << "-"
<< setw(2) << month << "-"
<< setw(2) << day << endl;
}

int main()
{
Date *dp = new Date;
dp->set(2000,12,12);
if( dp->isLeapYear())
dp->print();
else
cout << "not a LeapYear.";
return 0;
}

错误信息://怎么会有重载的错?真不明白。
C:\临时\f08032.cpp(21) : error C2511: 'isLeapYear' : overloaded member function 'bool (void)' not found in 'Date'
C:\临时\f08032.cpp(6) : see declaration of 'Date'
C:\临时\f08032.cpp(26) : error C2511: 'print' : overloaded member function 'void (void)' not found in 'Date'
...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
napoleonpan 2006-03-25
  • 打赏
  • 举报
回复
谢谢
0黄瓜0 2006-03-25
  • 打赏
  • 举报
回复
定义成员函数时,落了两个const

#include <iostream>
#include <iomanip>
using namespace std;

class Date
{
private:
int year, month, day;
public:
void set(int y, int m, int d);
bool isLeapYear() const;
void print() const;
};

inline void Date::set(int y, int m, int d)
{
year=y, month=m, day=d;
}

//inline bool Date::isLeapYear()
inline bool Date::isLeapYear() const
{
return ( (year%4==0 && year%100!=0) || year%400==0 );
}
//inline void Date::print()
inline void Date::print() const
{
cout << setfill('0');
cout << setw(4) << year << "-"
<< setw(2) << month << "-"
<< setw(2) << day << endl;
}

int main()
{
Date *dp = new Date;
dp->set(2000,12,12);
if( dp->isLeapYear())
dp->print();
else
cout << "not a LeapYear.\n";
return 0;
}

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧