在主模板的声明中不允许使用模板参数列表
我想编写一个模板类来计算元组的大小,但是编译时出现错误。
template <typename... Types>
struct tuple_size_<tuple<Types...>>{
static constexpr size_t value = sizeof... (Types);
};
I want to write a template class to calculate the size of tuple,but error occur when compiling.
template <typename... Types>
struct tuple_size_<tuple<Types...>>{
static constexpr size_t value = sizeof... (Types);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像是部分专业化,而没有先前的主模板,看起来像
template&lt; typname&gt; struct tuple_size_ {};
。This looks like a partial specialization without preceding primary template, which would look like
template <typename> struct tuple_size_ {};
.问题是您提供了部分模板专业化,但尚未声明相应的主模板。也就是说,您没有首先要专业的类模板。换句话说,首先没有专业的东西(类模板)是没有意义的。
解决这需要为小学模板提供声明:
The problem is that you're providing a partial template specialization but haven't declared the corresponding primary template. That is, there is no class template that you want to specialize in the first place. In other words, it doesn't make sense to specialize something(the class template in your case) that isn't there in the first place.
To solve this you need to provide a declaration for the primary class template: