【发布时间】:2026-02-02 06:25:01
【问题描述】:
我正在尝试在模板类中声明函数,以便函数声明依赖于模板类型参数。
template<typename T>
struct Block
{
static bool parse(int32_t index,
const typename std::enable_if<std::is_class<T>::value, T>::type& value);
static bool parse(int32_t index,
typename std::enable_if<!std::is_class<T>::value, T>::type value);
....
};
所以我想将Block<uint16_t> 和Block<std::string> 和parse() 声明为:
bool parse(int32_t index, const std::string& value);
or
bool parse(int32_t index, uint16_t value);
但我收到错误:'enable_if' cannot be used to disable this declaration
...typename std::enable_if<!std::is_class<T>::value, T>::type value);
您能帮我正确声明函数吗?
谢谢。
【问题讨论】: