【发布时间】:2025-12-12 12:55:02
【问题描述】:
我想这样声明:
template <typename T>
constexpr enable_if_t<is_integral_v<T>, int[]> foo = { 1, 2 };
template <typename T>
constexpr enable_if_t<is_floating_point_v<T>, int[]> foo = { 10, 20, 30 };
但是当我尝试I'm getting this error:
错误:
template<class T> constexpr std::enable_if_t<std::is_floating_point<_Tp>::value, int []> foo的重新声明
注意:之前的声明template<class T> constexpr std::enable_if_t<std::is_integral<_Tp>::value, int []> foo<T>
我觉得这应该是合法的,因为为任何给定的模板参数定义的foo 永远不会超过一个。我可以做些什么来帮助编译器理解这一点吗?
【问题讨论】:
-
@VTT 也许你能详细说明一下?你说这应该是可能的吗?如果有,怎么做?
标签: c++ templates overloading enable-if template-variables