Here's the code:
#include <utility>
#include <type_traits>
template <class T>
class ClassWithDisabledFoo
{
public:
template <class U = T, std::enable_if_t<std::is_integral<U>::value, int> = 0>
void foo(){}
};
class ClassWithFoo
{
public:
void foo(){}
};
class Derived: public ClassWithFoo, public ClassWithDisabledFoo<double>
{
};
void test()
{
Derived d;
d.foo();
}
At the point of calling d.foo()
, both clang and gcc say that the call to foo
is ambiguous, despite ClassWithDisabledFoo::foo
being disabled by enable_if
. If I move the foo
definition from ClassWithFoo
to Derived
, the code compiles.
Why doesn't this work and how can I make it work?