我有这段代码,我的期望是根据模板参数的类型,会有两个不同版本的运算符
()
。#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 :: operator()(const string&,int)'无法与'std :: enable_if_t <(!std :: is_pointer < _Tp> :: value),T> Impl :: operator()(const string&,int)
重载。
static_cast<T>();
是什么意思? - WhiZTiM