struct X{};
template<class T>
decltype(X() == int()) f(T const&){ return true; }
int main(void) {
X x;
f(x);
}
为什么? 为什么? 没有定义 operator {{/code> 任何地方 !
我真的想知道这里发生了什么, 提供MS Connect 的详细的错误报告。 我疯狂的旅程开始于
(注:无论是"http://ideone.com/JV6Co" rel="不随从无悔者">GCC ,还是Clang都不接受这个代码。 )
哦, Btw, 添加一个私有 < code> X( int) code> Central 导致编译失败 :
struct X{
X(){}
private:
X(int);
};
template<class T>
decltype(X() == int()) f(T const&){ return true; }
int main(void) {
X x;
f(x);
}
产出:
1>srcmain.cpp(12): error C2248: X::X : cannot access private member declared in class X
1> srcmain.cpp(4) : see declaration of X::X
1> srcmain.cpp(1) : see declaration of X