Pirx un[blog]ged

Mike is reading four blogs. This is none of them.

not so const

After debugging several hours a reasonable complex software, I was able to track down the problem to the following code:

int i = 42;
int const& r = i;
std::cout << r << std::endl;
i++;
std::cout << r << std::endl;

This prints in two sequential lines the value of a const refererence:

42
43

This reminds me what a const reference really means: A const reference cannot change the value of the reference. The value itself can.


comments powered by Disqus