Meet a very weird problem, anyone know what is the reason of this? the code is tested under Visual Studio 2012.
#include <iostream>
struct A {
int a;
};
struct B {
int b;
};
struct C : public A, public B {
int c;
};
int main() {
int C::*p = &C::b;
std::printf("%p\n", &C::b); //00000000
std::printf("%p\n", p); //00000004
return 0;
}
Note the possibly unexpected result of:
Which on VS2010 yields:
This indicates that the resulting type for &C::b is a member pointer on type B. Since C is derived from B the pointer is freely convertible to a member pointer on type C. This explains the difference between the two values you see. &C::b is a member function pointer on type B, int C::*p is a member function pointer on type C.