Given a base class and a derived class, which both provide conditionally enabled operators for specific parameter types using SFINAE:
#include <type_traits>
class Base
{
public:
template<class T, std::enable_if_t<std::is_scalar_v<T>>* = nullptr>
void operator>>(T& value) {
}
};
class Derived: public Base
{
public:
using Base::operator>>;
template<class T, std::enable_if_t<!std::is_scalar_v<T>>* = nullptr>
void operator>>(T& value) {
}
};
int main(int argc, char *argv[])
{
int foo;
Base base;
base >> foo; // this works
Derived derived;
derived >> foo; // this doesn't work, the operator from the base class is not considered
}
then calling an operator defined in the base class on an instance of the derived class will not work, even though it should have been made visible by the appropriate using Base::operator>>;
declaration. Why? How can the operator from the base class be made usable without verbosely repeating the declaration/definition?
The problem does not occur if the operator in question is not a template in the base class.
Edit: Tested with msvc 15.9.7 as well as clang.