【发布时间】:2015-02-19 11:51:48
【问题描述】:
在模板模板参数的情况下,是否可以使void foo 采用通用引用而不是右值引用,如下面的代码所示?
#include <iostream>
#include <string>
using namespace std;
template <int I>
struct s
{
string str;
};
template <template<int> class T, int U>
void foo(T<U>&& param)
{
cout << param.str << endl;
}
int main()
{
s<5> thing;
foo( thing );
}
我收到following error:
error: cannot bind 's<5>' lvalue to 's<5>&&'
【问题讨论】:
-
没有。转发引用(所谓的“通用引用”的官方名称)必须是
T&&,其中T是正在推导的模板类型参数。
标签: c++ c++11 rvalue-reference forwarding-reference