I have the following sample code:
class Serializable {};
class MyData : public Serializable {};
void GetData( Serializable& ) {}
template<typename T>
void GetData( T& data )
{
std::istringstream s{"test"};
s >> data;
}
int main()
{
MyData d;
GetData(d);
}
Based on overload resolution rules, the non-template version should be preferred because the base class is of type Serializable
. However, I expect SFINAE to kick in when there are errors in the template version when it is instantiated for overload resolution (because if the >> operator is not defined for a type, it should not be considered).
Why is it still failing even though the template won't be used?
See Question&Answers more detail:os