【发布时间】:2012-01-13 05:54:39
【问题描述】:
template<class U>
void f( U && v)
{
std::cout << typeid(v).name() << "\n"; //'int' in both cases
if( boost::is_same<int&&,U>::value )
{
std::cout << "reach here\n"; //only with f<int&&>(int(1));
}
}
int main()
{
f(int(1));
f<int&&>(int(1));
std::cin.ignore();
}
当我没有明确使用f<int&&>时,为什么v参数被解释为int?
有什么区别 ? (MVS2010编译)
我的猜测是 First 作为右值传递,第二个作为右值引用传递,并且都正确绑定到右值引用,对吗?
谢谢。
【问题讨论】:
标签: c++ templates rvalue-reference