Suppose I define a function in C++ as follows:
void foo(int &x) const {
x = x+10;
}
And suppose I call it as follows:
int x = 5;
foo(x);
Now typically (without the const
keyword), this would successfully change the value of x
from the caller's perspective since the variable is passed by reference. Does the const
keyword change this? (i.e. From the caller's perspective, is the value of x
now 15?)
I guess I'm confused as to what the const
keyword does when it is appended to the end of a function definition... any help is appreciated.