这是我有点奇怪的代码:
template <typename T&>
class A {
public:
void b(typename std::enable_if<!std::is_pointer<T>::value, T>;::type o) {}
void b(typename std::enable_if<std::is_pointer<T>::value, T>;::type o) {}
};
template <typename T>
void b(typename std::enable_if<!std::is_pointer<T>::value, T>::type o) {}
template <typename T>
void b(typename std::enable_if<std::is_pointer<T>::value, T>::type o) {}
如果我ifdef退出方法b并调用b<int *>(pi) where piis int *,一切都会编译。
如果我ifdef退出函数b(类外)并调用A<int *> a; a.b(pi),我会收到以下错误:
error: no type named 'type' in 'std::__1::enable_if<false, int *>'
为什么不一致以及如何解决问题以便我可以使用 A 中的方法?