Consider the following:
#include <iostream>
class A {
public:
virtual void foo(){ std::cout << "A::foo" << std::endl; }
void bar(){ std::cout << "A::bar" << std::endl; }
};
class B : public A {
public:
void foo(){ std::cout << "B::foo" << std::endl; }
void bar(){ std::cout << "B::bar" << std::endl; }
};
typedef void (A::*a_func_ptr)(void);
int main() {
a_func_ptr f = &A::foo;
a_func_ptr g = &A::bar;
B b;
A a;
(b.*f)();
(b.*g)();
(a.*f)();
(a.*g)();
}
Output:
B::foo
A::bar
A::foo
A::bar
Both member pointers are of the same type, yet both correctly routed the call in every cases.
Somehow, the generated programme must know when a pointer to method is actually a simple method or a virtual one. Thus the runtime representation of a method pointer has to include more information to handle the second case.
Remark: the size seems to be implementation dependent (I get 8
on my system).