【发布时间】:2019-06-26 02:17:43
【问题描述】:
template<typename T>
void f(T a, const T& b)
{
++a; // ok
++b; // also ok!
}
template<typename T>
void g(T n)
{
f<T>(n, n);
}
int main()
{
int n{};
g<int&>(n);
}
请注意:b 属于const T&,++b 可以!
为什么const T& 不确定是 const?
【问题讨论】:
标签: c++ templates constants function-templates const-reference