|
||||
|
Section 13:
|
[13.7] Can I create a operator** for "to-the-power-of" operations?
Nope. The names of, precedence of, associativity of, and arity of operators is fixed by the language. There is no operator** in C++, so you cannot create one for a class type. If you're in doubt, consider that x ** y is the same as x * (*y) (in other words, the compiler assumes y is a pointer). Besides, operator overloading is just syntactic sugar for function calls. Although this particular syntactic sugar can be very sweet, it doesn't add anything fundamental. I suggest you overload pow(base,exponent) (a double precision version is in <cmath>). By the way, operator^ can work for to-the-power-of, except it has the wrong precedence and associativity. |
|||