简体   繁体   中英

C++ operators overloaded as a consequence ('+', '+=')

When I overload, lets say, the '+' operator for a class in C++

MyClass MyClass::operator+(MyClass _c){
    //code here
}

Does it automatically apply to the '+=' operator? Does the compiler automatically substitute that for its longer conuterpart (a+=b <--> a=a+b)? Or is it a runtime operator function?

No. It doesn't. You need to overload those as well.

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.

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