मेरे पास यह कोड है, मेरी उम्मीद है कि टेम्पलेट पैरामीटर के प्रकार के आधार पर ऑपरेटर ()
के दो अलग-अलग संस्करण होंगे।क्यों सक्षम नहीं है Iif यहां काम कर रहा है?
#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()
{
}
इसके बजाय मैं एक त्रुटि संकलन मिलती है: '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 उठाओ: क्या 'static_cast है();'? –
WhiZTiM
@WhiZTiM [ftfy] (http://coliru.stacked-crooked.com/a/4418f30d119f86fe) –