【发布时间】:2021-08-16 13:03:08
【问题描述】:
我很困惑为什么下面的代码不起作用?
编译器说: 错误:无法将“int&”类型的非常量左值引用绑定到“int”类型的右值 6 |常量 T a = 1;
template<typename T>
void f(T&& t)
{
const T a = 1;
}
int main()
{
int i;
int& k = i;
f(k);
}
【问题讨论】:
-
const typename std::remove_reference<decltype(t)>::type& a = 1;