【发布时间】:2015-07-21 12:29:42
【问题描述】:
我以前经常使用 SFINAE,但我有一个非常简单的示例,我今天无法运行。
class X
{
public:
template <typename CHECK, typename = typename std::enable_if< std::is_floating_point<CHECK>::value, void>::type >
void Do()
{
std::cout << "yes" << std::endl;
}
template <typename CHECK, typename = typename std::enable_if< !std::is_floating_point<CHECK>::value, void>::type>
void Do()
{
std::cout<< "no" << std::endl;
}
};
int main()
{
X x;
x.Do<float>();
}
错误:
src/main.cpp:20:18: 错误:'template void X::Do()' 不能重载
src/main.cpp:14:18: 错误: with 'template void X::Do()' 无效的 Do()
我想用 enable_if 禁用任何过载,但它不起作用...
知道我今天做错了什么吗?
【问题讨论】: