I would like to override operator * for my class. I know how to handle * for MyClass * MyClass but how can i implement this for having possibility to multiply for example:
7 * MyClass
7 is lets say double and MyClass is object of MyClass,
thanks for help
When you provide an operator for your class, the parameter types for the operator implementation control which situations you’re handling.
To illustrate:
This method defines what to do if you want to add two
Complexnumbers.If you tried to use this with (say) a
doubleand aComplex, compilation would fail.In your case, you need just declare both versions: