我有关于成员指针的问题.以下代码无法使用Oracle Solaris Studio 12.2的CC和cygwin GCC 4.3.4进行编译,但与Microsoft Visual C++ 2010一起使用:
struct A {
int x;
};
struct B : public A {
};
template<typename T> class Bar {
public:
template<typename M> void foo(M T::*p);
};
int main(int, char *[]) {
Bar<B> bbar;
bbar.foo(&B::x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在倒数第二行,上面提到的两个编译器都找不到匹配项Bar<B>::foo(int A::*).我写了一个简单的测试来确认表达式的类型&B::x实际上是int A::*:
// ...
static void foo(int A::*p) {
std::cout << "A" << std::endl;
}
static void foo(int B::*p) {
std::cout << "B" << std::endl;
}
int main(int, …Run Code Online (Sandbox Code Playgroud)