Here I am unable to understand why Stroustrup has mentioned "provided
lvalue has no side-effects". Isn't the expression ++lvalue the same as
lvalue = lvalue + 1 always ? Kindly clarify with an example.
Thanks
V.Subramanian
For example, suppose you have an object v, of a type similar to
std::vector<int>. You would expect ++v[0] to be equivalent to v[0] = v[0] +
1. But clearly that assumes that doing v[0] doesn't have some side-effect,
like doing std::cout << "Hey, operator[] is called".
Does that answer your question?
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
int* p;
++(*p ++); // which is NOT the same as:
*p ++ = *p ++ + 1; // undefined behavior...
--
James Kanze