I want to implement "operator * " overloading INSIDE my class, so I would be able to do the following:
Rational a(1, 2), b;
b = 0.5 * a; // b = 1/4
Notice that b is on the right side, is there a way to do such a thing inside "Rational" class?
No. You must define operator*
as a free function. Of course, you could implement it in terms of a member function on the second argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With