我如何使用可变参数模板声明std :: tuple? [英] How I declare a std::tuple using variadic templates?
本文介绍了我如何使用可变参数模板声明std :: tuple?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许我在这里很幼稚,但是我相信下面的代码应该可以编译:
Perhaps I being naive here, but I believe the following code should compile:
template <typename ... T>
struct Test {
std::tuple<T> foo;
};
int main() {
struct Test<int, long> test;
return 0;
}
相反,g ++抱怨:
test.cpp:5: error: parameter packs not expanded with '...':
test.cpp:5: note: 'T'
我想念什么?
推荐答案
您可以通过使用 ...
:
template <typename... T>
struct Test
{
std::tuple<T...> foo;
// ^^^^
};
这篇关于我如何使用可变参数模板声明std :: tuple?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文