我有一个重载的运算符:
rectangletype rectangletype::operator+(const rectangletype& rect) const
{
rectangletype temprect;
temprect.length = length + rect.length;
return temprect;
}
这是主要的:
int main()
{
rectangletype r1(23);
rectangletype r2(27);
rectangletype r3 = r1 + r2;
r3.print();
}
在重载的运算符函数中,当我使用this-> length而不是length时,它给出的结果相同,但是否一样?
覆盖运算符时,this
关键字引用语句中运算符左侧的对象。在重载函数中,可以显式使用this->
,但这是隐含的,因此不是必需的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句