I have the following code:
void g(int& i) {
std::cout << "g(int&)" << std::endl;
}
void g(int&& i) {
std::cout << "g(int&&)" << std::endl;
}
void f(int&& i) {
g(i);
}
int main() {
f(3); // g(int&)
}
As you can see, the parameter i
in the f
function is an rvalue reference, so when it calls g(i)
, the corresponding g
function which takes an rvalue reference should be called(i.e. the result should be g(int&&)
), but this is not the case. Actually, g(int& i)
was called. Why?
My guess is that when we are inside the f
function, i
becomes an lvalue instead of an rvalue, is that correct? Are lvalue and rvalue interchangeable?