c++ operator overloading
i'm not sure if what im talking about is an operator overloading question. is it possible to overload keywords in C++??
for example : i need 开发者_开发技巧to write loopOver(i=0; ;i++) instead of for(i=0;;i++) ?? is that possible in C++and i need to have something like 2 addTo 2 instead of 2 + 2
please help thanks in advance
You can't do that with operator overloading (you can't change the names of the operators, only how they work).
However, evil as it is, if you don't want to change the way they work (just the names), you would be able to achieve things like this using macros:
#define loopOver for
#define addTo +
(Use macros with extreme care though - if used incorrectly they can cause hideous problems)
You can use #define directive
#define loopOver for
#define addTo +
But this is just bad!
And no - this is no operator overloading question. Here You have some informations: http://en.wikibooks.org/wiki/C%2B%2B_Programming/Operators/Operator_Overloading
精彩评论