std :: enable_if: parameter vs template parameter
Ich erstelle ein Eingabeprüfprogramm, das bestimmte Funktionen für Integer und / oder Double haben muss (zum Beispiel sollte 'isPrime' nur für Integer verfügbar sein).
Wenn ich benutzeenable_if
als parameter funktioniert es einwandfrei:
template <class T>
class check
{
public:
template< class U = T>
inline static U readVal(typename std::enable_if<std::is_same<U, int>::value >::type* = 0)
{
return BuffCheck.getInt();
}
template< class U = T>
inline static U readVal(typename std::enable_if<std::is_same<U, double>::value >::type* = 0)
{
return BuffCheck.getDouble();
}
};
aber wenn ich es als Template - Parameter benutze (wie auf gezeigt)http://en.cppreference.com/w/cpp/types/enable_if )
template <class T>
class check
{
public:
template< class U = T, class = typename std::enable_if<std::is_same<U, int>::value>::type >
inline static U readVal()
{
return BuffCheck.getInt();
}
template< class U = T, class = typename std::enable_if<std::is_same<U, double>::value>::type >
inline static U readVal()
{
return BuffCheck.getDouble();
}
};
dann habe ich folgenden fehler:
error: ‘template<class T> template<class U, class> static U check::readVal()’ cannot be overloaded
error: with ‘template<class T> template<class U, class> static U check::readVal()’
Ich kann nicht herausfinden, was in der zweiten Version falsch ist.