In Python, we have a nice simple syntax to take an arbitrary int / float value. Namely, for you who are not Python programmers, we can have the following statement:
y = 2 ** 3 print y
This will print 8 on the console and has good syntax since there is a built-in βpowerβ statement. Is it possible to overload "**" as a single statement in C ++? In particular, I want to do something like this:
int a = 2; int b = 3; cout << (a**b) << endl;
or, if this is not possible, something like this:
MyInt a = new MyInt(2);
They should also print 8 for the console. I understand that it would be much easier to redefine the ^ operator to do the same, but what interests me most is if I can overload the **. Will the operator "*" (for the case of the class MyInt, if it is a member function), have to see if the argument was another "*", since I do not know how to specify "**" as a single operator? Is it even possible to pass an operator as an argument?
Additional / bonus condition, if possible (as if I had not said enough): No macros !!!
source share