【发布时间】:2017-09-05 16:13:48
【问题描述】:
我正在尝试在可变参数模板中实现一个元函数(?),以在编译时计算几种类型的 sizeof 的最大值。
template<typename... Ts> struct MaxSizeof {
static constexpr size_t value = 0;
};
template<typename T, typename... Ts> struct MaxSizeof {
static constexpr size_t value = std::max(sizeof(T), typename MaxSizeof<Ts...>::value);
};
但我遇到了一些奇怪的错误:
MaxSizeof.h(7): error C3855: 'MaxSizeof': template parameter 'Ts' is incompatible with the declaration
MaxSizeof.h(7): error C2977: 'MaxSizeof': too many template arguments
MaxSizeof.h(5): note: see declaration of 'MaxSizeof'
您能帮我修改一下代码吗?
编译器为MSVC++2017工具集v141。
【问题讨论】:
-
您在 constexpr 之前是否缺少 static?
-
@Phil1970,谢谢,我已经更新了代码和错误消息。
标签: c++ c++11 templates metaprogramming variadic-templates