帮我看看这个小程序 错误在哪里

fengtao612 2007-07-02 12:10:52
#include<iostream>
#include<stdlib.h>
using namespace std;
class time
{public:
time():h(0),m(0),s(0){};
//~time();
int seth();//设置小时
int setm();//设置分钟
int sets();//
void gettime();
private:
int h;
int m;
int s;
};

int time::seth()
{
cin>>h;
return h;
}
int time::setm()
{
cin>>m;
return m;
}
int time::sets()
{
cin>>s;
return s;
}
void time::gettime()
{cout<<seth()<<":"
<<setm()<<":"
<<sets()<<":";
}

int main()
{
time t;//说这行出了问题
cout<<t.gettime();
t.seth();
t.setm();
t.sets();
cout<<t.gettime();
system("pause");
return 0;
}





题是错误是:41 C:\Documents and Settings\user\桌面\新建文件夹\program\time.cpp expected `;' before 't'









看看这个程序 如果类的名称是a 能够编译通过 可是类名是 time 的话 不能通过

#include<iostream>
#include<stdlib.h>
using namespace std;
class a
{

public:
a(){cout<<"creating a new class";}

};



int main()
{a a1;
system("pause");
return 0;
}

...全文
209 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cwuliao 2007-07-04
  • 打赏
  • 举报
回复
time():h(0),m(0),s(0){};
分号多了吧
CowmanGens 2007-07-04
  • 打赏
  • 举报
回复
第一个程序去掉cout<<t.gettime(); 前面的cout<<,直接改为:t.gettime();
SoledadWith 2007-07-02
  • 打赏
  • 举报
回复
第一个程序去掉cout<<t.gettime(); 前面的cout<<,直接改为:t.gettime();
yamanakajp 2007-07-02
  • 打赏
  • 举报
回复
time在C++中是关键词
改用_Time或其他名字
taodm 2007-07-02
  • 打赏
  • 举报
回复
不要用time,很可能与库文件里的东西重名了。

64,654

社区成员

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

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