I'm trying to overload operator += on a class named 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..?
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 +=.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.