The first lines of code will return 112
but why? 1
is not supposed to be of type int&&
? And why it is working in the second example of code i.e. returning 312
?
void fun(int&) { cout << 1; }
void fun(int const&) { cout << 2; }
void fun(int&&) { cout << 3; }
template
<typename T>
void fun2(T&& t) { fun(t); }
int main() {
int x{};
int const y{};
fun2(1);
fun2(x);
fun2(y);
}
void fun(int&) { cout << 1; }
void fun(int const&) { cout << 2; }
void fun(int&&) { cout << 3; }
template
<typename T>
void fun2(T&& t) { fun(std::forward<T>(t)); }
int main() {
int x{};
int const y{};
fun2(1);
fun2(x);
fun2(y);
}