C++ 对象作为函数参数

C++ 对象作为函数参数,c++,C++,我写了一个简单的程序 我得到这个错误: 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

我写了一个简单的程序

我得到这个错误:

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;
}
#包括
使用名称空间std;
上课时间
{
整小时;
int-min;
公众:
void gettime(inth,intm)
{
小时=小时;
min=m;
}
void puttime()
{

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


这是您应该避免使用命名空间std;
的一个主要原因。请记住,有一个名为的标准函数


这是您应该避免使用命名空间std;的一个主要原因。这里的putime()必须是b.puttime()。否则编译的代码必须是b.puttime()。否则,使用命名空间std;编译的代码可能会引入一个名为
time()的函数
从标准库中。找到一个新名称。
Time
浮现在脑海中。将
Time
改为自始至终说
Time
,并修复打字错误
b.putime();
->
b.puttime()
使用nampespace std
的另一种方法是
使用std::cout
使用std::endl
。也就是说,只将您实际使用的std中的内容纳入范围。关于名称
时间
,我建议两件事:1)将类
时间
放在命名空间中。2)不要使用ode>使用namespace std
指令。
使用namespace std;
可能会从标准库中引入一个名为
time()
的函数。找到一个新名称。
time
浮现在脑海中。将
time
改为自始至终说
time
,并修复打字错误
b.puttime();
->
b.puttime()
使用nampespace std
的另一种方法是
使用std::cout
使用std::endl
。也就是说,只将您实际使用的std中的内容纳入范围。关于名称
时间
,我建议两件事:1)将类
时间
放在命名空间中。2)不要使用ode>使用命名空间std
指令。