考虑以下代码:
#include <iostream>
template<typename T>
void inc1(T&& x)
{
    T y = x;
    ++y;
}
template<typename T>
void inc2(T& x)
{
    T y = x;
    ++y;
}
int main()
{
    int a = 10;
    inc1(a); // a is now 11
    int b = 10;
    inc2(b); // b remains 10
}
替换后我们有
void inc1(int& x)
{
    int& y = x; // reference to x
    ++y; // increments x
}
void inc2(int& x)
{
    int y = x; // copy of x
    ++y; // increments the copie
}
In inc1,x是类型int&,因为int&和T&&都是引用,但不是两者都是 r 值。
类似地, in inc2,x属于 类型int&,因为int&和T&都是引用,但不是两者都是 r 值。
我的问题是y:为什么 in是类型inc1,而 in是类型?yint&inc2yint
我在 gcc 4.8.1 和 microsoft v110 和 v120_ctp 上都观察到了这一点。