0

I came across this question:

X *= y is an example of

  • Arithmetic assignment operations

  • Assignment operator

  • Overloading arithmetic operations with assignment operator

  • All of the above

I expected the answer to be "Assignment operator", but the answer is given as "Overloading arithmetic operations with assignment operator".

Can someone explain how we are doing operator overloading in the *= operator?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
proglove
  • 15
  • 5
  • 1
    Did it give any context, such as a definition of the type of `X` and/or `y`? Without that, the question is basically unanswerable. – Jerry Coffin Apr 06 '21 at 19:14
  • 1
    `*=` is a *compound assignment operator*. For arithmetic types, it performs BOTH multiplication AND assignment, where `X *= Y` is equivalent to `X = X * Y`. For user-defined types, it is an overridable operator, so its actual behavior depends on the type's implementation. – Remy Lebeau Apr 06 '21 at 19:25
  • For an example of "Overloading arithmetic operations with assignment operator", write a `Fractions` class and overload `operator*=` or `operator+=`. – Thomas Matthews Apr 06 '21 at 19:34

0 Answers0