1

我写了一个简单的程序。

我收到此错误:

time.cpp: In function ‘int main()’:
time.cpp:22:9: error: expected ‘;’ before ‘a’
time.cpp:23:4: error: ‘a’ was not declared in this scope
time.cpp:24:4: error: ‘b’ was not declared in this scope
time.cpp:25:4: error: ‘c’ was not declared in this scope

这是我的代码:

#include<iostream>
using namespace std;
class time
{
    int hour;
    int min;

public:
    void gettime(int h,int m)
    {
        hour=h;
        min=m;
    }

    void puttime()
    {
        cout<<hour<<endl<<min;
    }

    void sum(time x,time y)
    {
        min=x.min+y.min;
        hour=min/60;
        min=min%60;
        hour=hour+x.hour+y.hour;
    }
};

int main()
{
    time a,b,c;
    a.gettime(2,45);
    b.gettime(3,35);
    c.sum(a,b);
    a.puttime();
    b.putime();
    c.puttime();
    return 0;
}
4

2 回答 2

5

请记住,有一个名为 的标准函数time

这是您应该避免的主要原因之一using namespace std;

于 2013-01-29T10:21:22.693 回答
1

b.putime() 必须是 b.puttime() 这里。否则编译此代码

于 2013-01-29T10:26:02.970 回答