我希望能够基于这样的模板参数禁用重载的运算符功能
template <int T>
class Foo {
int v;
template <std::enable_if_t<T == 0, int> = 0>
Foo operator-() const
{
return {-v};
}
};
但是当我尝试实例化一个Foo的值时,该值会禁用该功能(即1),编译器会抱怨
Foo<0> f0; // This compiles
Foo<1> f1; // This does not
我不是要调用禁用的功能,而是编译器抱怨无法访问它。
对此行为有任何解释吗?