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
-
1You could use a macro #define loopOver for #define addTo +OneOfOne– OneOfOne2009年12月12日 09:56:06 +00:00Commented Dec 12, 2009 at 9:56
-
2Do you have a hidden reason for wanting to do this?Artelius– Artelius2009年12月12日 09:58:33 +00:00Commented Dec 12, 2009 at 9:58
-
2Why do you "need to write" this? With a background you might get more helpful answers.Georg Fritzsche– Georg Fritzsche2009年12月12日 09:58:38 +00:00Commented Dec 12, 2009 at 9:58
-
its just a homework . :D , no hidden reason or something .Moayyad Yaghi– Moayyad Yaghi2009年12月12日 10:39:54 +00:00Commented Dec 12, 2009 at 10:39
-
What a bad homework assignment.Charles Salvia– Charles Salvia2009年12月12日 11:03:37 +00:00Commented Dec 12, 2009 at 11:03
2 Answers 2
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)
3 Comments
for keyword.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