首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

大家好,小弟我有一个关于this指针的有关问题想要请问

2012-09-07 
大家好,我有一个关于this指针的问题想要请教!C/C++ codeclass time{private:int hoursint minutespublic

大家好,我有一个关于this指针的问题想要请教!

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;}
[解决办法]
探讨
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);
……

[解决办法]
[Quote=引用:]

time和Time是不同的,会编译不过的。
time类的结尾要以分号结束,否则会编译不过的。

t 就是参数的名字,当在main函数或某处出现
[code=C++]time a;
time b;
time c;
a = b + c;[/code]
时,c就是那个t
[/Quote]

注意+是二元运算符,只有一个参数时,是出现在右边的那个,比如c

热点排行