我正在使用可变参数模板,目前正在尝试operator<<
为元组实现。
我试过下面的代码,但它没有编译(GCC 4.9 with -std=c++11)。
template<int I, typename ... Tlist>
void print(ostream& s, tuple<Tlist...>& t)
{
s << get<I>(t) << ", ";
if(I < sizeof...(Tlist)){
print<I+1>(s,t);
}
}
template<typename ... Tlist>
ostream& operator<<(ostream& s, tuple<Tlist...> t)
{
print<0>(s,t);
return s;
}
错误消息非常神秘且冗长,但它基本上表示没有匹配的函数调用获取。有人可以向我解释为什么吗?谢谢。
编辑:这是我正在使用的模板实例化
auto t = make_tuple(5,6,true,"aaa");
cout << t << endl;