Sunday, July 25, 2010

Modifying Temporary Values

For fundamental types, like int and float, you are not allowed to modify temporary values, while you are allowed to modify the temporary values of classes and structs.

This sometimes shows up when porting code from a compiler that uses classes for vector iterators, to pointers as vector iterators. In the first case, ++v.begin() would compile, while in the second case it wouldn't, because you cannot modify the temporary created from b.begin().

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis, Addison-Wesley, 1999, p. 258.

No comments:

Post a Comment