0
这里是我想要达到的MCVE:为什么我的SFINAE开关不工作?
#include <limits>
#include <iostream>
// enable_if (I'm stuck with a c++98 compiler)
template<bool B, class T = void> struct enable_if {};
template<class T> struct enable_if<true, T> { typedef T type; };
// sfinae
template<typename T> const char*
f(typename enable_if<std::numeric_limits<T>::is_integer, T>::type t) { return "sfinae"; }
template<typename T> const char*
f(T t) { return ""; }
// test
int main()
{
std::cout << f(3) << "\n"; // returns an empty string
std::cout << f(3.0) << "\n"; // returns an empty string
}
我期待调用f(3)
返回"sfinae"
。我究竟做错了什么?
对于第一个要调用的版本,我必须手动调用f<int>(3)
。我很困惑。
事实上(感谢),但为什么呢? – YSC
编辑说明... –
@YSC:完成,有帮助吗? –