我试了,你的代码可以运行,好像没有任何问题。
#include
using namespace std;
class clock
{
public:
clock(int newh=0, int newm=0, int news=0);
clock(clock &first);
void settime(int newh, int newm, int news);
void showtime();
private:
int hour, minute, second;
};
clock::clock(int newh, int newm, int news)
{
hour = newh;
minute = newm;
second = news;
}
clock::clock(clock &first)
{
hour = first.hour;
minute = first.minute;
second = first.second;
}
void clock::settime(int newh, int newm, int news)
{
hour = newh;
minute = newm;
second = news;
}
void clock::showtime()
{
cout << hour << ":" << minute << ":" << second<}
int main()
{
cout << "Initialization:\n";
clock myclock(0, 0, 0), herclock;
myclock.showtime();
herclock.showtime();
int h, m, s;
cout << "Time set:" << endl << "hour:";
cin >> h;
cout << "minute:";
cin >> m;
cout << "second:";
cin >> s;
myclock.settime(h, m, s);
cout << "\nTime show myclock:"<myclock.showtime();
herclock = myclock;
cout << "Time show herclock:" << endl;
herclock.showtime();
clock hisclock(herclock);
cout << "Time show hisclock:" << endl;
hisclock.showtime();
return 0;
}
如果你检查了确定没有语法错误,这种报错一般是文本里有编译器识别不了的字符,而且这玩意显示不出来,试试改变编译器的编码格式或者把文本用word打开显示所有的非文字字符看看
贴上来的程序看不出有什么问题。
错误信息清楚地说,文件 “源3_12_2.cpp” 中第8行 花括号 有错,但你第8行前后 都没有 花括号 { 。 你贴上来的程序 与要查找的程序 不是同一个程序吧?
clock 定义最后的分号去掉看看?