You can overload the common arithmetic operators like +,-,* to perform different operations with the objects of the class.... but is it possible to overload the power or exponential operator '^' as well using the usual operator overloading procedure?
C++ operator overloading?
You can overload ^ but there is one important thing you need to remember. Normally ^ is the bitwise xor operator and it has a lower precedence than the arithmatic operators and you cannot change precedence by overloading. So
a ^ b - c;
is not going to do what you expect unless you use parenthesis, namely
(a ^ b) - c;
Reply:Yes, but you need to override the math library. You can write your own library that calls the math library for the basic and then overload it.
gladiolus
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment