Modifying reference member from const member function in C++

Because you are not changing any variable in X. Actually, you are changing _y which is an outsider with respect to your class. Don’t forget that:

y = newY;

Is assigning the value of newY to the variable pointed by y, but not the references them selves. Only on initialization the references are considered.

Leave a Comment