Bu koda sahibim, beklenti, şablon parametresinin türüne göre operatörün iki farklı sürümü olan ()
olacaktır. Neden enable_if burada çalışmıyor?
#include <string>
#include <type_traits>
template<typename T>
struct Impl
{
std::enable_if_t<!std::is_pointer<T>::value,T> operator()(const std::string& key, int node)
{
return static_cast<T>();
}
std::enable_if_t<std::is_pointer<T>::value,T> operator()(const std::string& key, int node)
{
return new T();
}
};
int main()
{
}
Onun yerine bir hata derleme olsun:
'std::enable_if_t<std::is_pointer<_Tp>::value, T> Impl<T>::operator()(const string&, int)' cannot be overloaded with 'std::enable_if_t<(! std::is_pointer<_Tp>::value), T> Impl<T>::operator()(const string&, int)'
Nit Çekme: nedir? Static_cast(); '? –
WhiZTiM
@WhiZTiM [ftfy] (http://coliru.stacked-crooked.com/a/4418f30d119f86fe) –