Sharpdew wrote:
class Test
{
double i;
public:
void fun(){}
void foo(void)
{
cout << "as";
}
};
int main()
{
Test t;
t.foo; // mean what?
Test::foo; // mean what?
The last two expressions mean nothing. They are illegal. You can make a
call:
t.foo()
Or take the address of the function:
&Test::foo
cout << &Test::foo << endl; // output 1, why?
cout << &Test::fun << endl; // output 1, too, why?
return 0;
}
Pointer to members are not really memory address in the strict sense.
You can think of it as a relative address (to whatever instance of that
type.)
Therefore, pointer to member cannot be converted to a normal pointer,
say, void*. Therefore it is not outputted as a normal pointer.
If you are so interested in the bit sequence of these pseudo pointers
you can do a forced conversion using reinterpret_cast, like so:
int main()
{
typedef void (Test::*tf)(void);
tf p1 = &Test::foo;
tf p2 = &Test::fun;
cout << *reinterpret_cast<void**>(&p1) << endl;
cout << *reinterpret_cast<void**>(&p2) << endl;
}