大家好,小弟我有一个关于this指针的有关问题想要请问
大家好,我有一个关于this指针的问题想要请教!
这里的(const Time &t)作为参数是什么意思,可以详细的解释一下么,t是什么?
------解决方案--------------------
time和Time是不同的,会编译不过的。
time类的结尾要以分号结束,否则会编译不过的。
t 就是参数的名字,当在main函数或某处出现
[code=C++]time a;
time b;
time c;
a = b + c;[/code]
时,c就是那个t
------解决方案--------------------
- C/C++ code
class time { private: int hours; int minutes; public: Time(); Time (int h , int m =0); void AddMin (int m); void AddHr(int h); void Reset (int h = 0, int m = 0); Time operator+(const Time &t)const; void Show()const; }
这里的(const Time &t)作为参数是什么意思,可以详细的解释一下么,t是什么?
------解决方案--------------------
time和Time是不同的,会编译不过的。
time类的结尾要以分号结束,否则会编译不过的。
t 就是参数的名字,当在main函数或某处出现
[code=C++]time a;
time b;
time c;
a = b + c;[/code]
时,c就是那个t
------解决方案--------------------
- C/C++ code
Time operator+(const Time &t)const { Time t2; t2.hours=this.hours+t.hours; t2.seconds=this.seconds+t.seconds; return t2; }
------解决方案--------------------
------解决方案--------------------
[Quote=引用:]
time和Time是不同的,会编译不过的。
time类的结尾要以分号结束,否则会编译不过的。
t 就是参数的名字,当在main函数或某处出现
[code=C++]time a;
time b;
time c;
a = b + c;[/code]
时,c就是那个t
[/Quote]
注意+是二元运算符,只有一个参数时,是出现在右边的那个,比如c