Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "+=" when "+" is overloaded in a class function?

const function operator+(const function *) const;

What will happen if you do: x += y; ...when x and y are of the same class. Does it still work in this context or does it have to be x + y;?

like image 487
lejit158 Avatar asked Jul 17 '26 14:07

lejit158


1 Answers

They are distinct and unrelated (as far as compiler is concerned)

Though, if you overload 1 of them, it is probably worth also overloading the other for consistency

btw. Here is very good explanation of operator overloadings: https://stackoverflow.com/a/4421719/3595112

like image 159
industryworker3595112 Avatar answered Jul 20 '26 07:07

industryworker3595112



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!