简体   繁体   English

重载运算符+ = c ++时出错

[英]Error while overloading operator += c++

I'm trying to overload operator += on a class named Movie: 我试图在名为Movie的类上重载运算符+ =:

Movie& operator+=(const Movie& other)
{
 *this=*this+other;
 return*this;}

gives me error Movie.h:47:10: error: with 'Movie& Movie::operator+=(const Movie&)' how do i over load it..? 给我错误Movie.h:47:10:错误:使用“ Movie&Movie :: operator + =(const Movie&)”,我如何过载它?

Despite reported problem, the code is structurally incorrect. 尽管报告了问题,但是代码在结构上是不正确的。 It calls an assignment operator inside += operation, which is not neccessary and is just a performance drag. 它在+ =操作中调用赋值运算符,这不是必需的,仅仅是性能上的拖累。 Instead, operator += should be properly coded with modification to the object, and operator + expressed in the terms of +=. 取而代之的是, operator +=应该正确编码,并带有对对象的修改,并且operator +用+ =表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM