我想声明这样的事情:
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 };
但是当我尝试时,我得到了这个错误:
错误:重新声明
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
我觉得这应该是合法的,因为任何给定的模板参数都不会定义多个。我能做些什么来帮助编译器理解这一点吗?