std :: enable_if: parametr vs parametr szablonu

Buduję kontroler wejściowy, który musi mieć określone funkcje dla liczby całkowitej i / lub podwójnej (na przykład „isPrime” powinien być dostępny tylko dla liczb całkowitych).

Jeśli używamenable_if jako parametr działa doskonale:

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();
   }   
};

ale jeśli używam go jako elementu wzorcowego (jak pokazano nahttp://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();
   }
};

wtedy mam następujący błąd:

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()’

Nie mogę zrozumieć, co jest nie tak w drugiej wersji.

questionAnswers(3)

yourAnswerToTheQuestion