The size of a class containing any virtual functions
varies when compiled in 32-bit mode versus 64-bit mode. The difference
in size is caused by the virtual table pointer (a pointer to an internal
compiler table) in the class object. (The pointer is created for any
class containing one or more virtual functions.)
When compiling the following example in 32-bit
mode, the output is 8. In 64-bit mode, the output is 16.
extern "C" int printf(const char *,...);
class A {
int a;
public:
virtual void foo(); //virtual function foo, part of class A
};
void A::foo() {
return;
}
int main() {
printf("%d\n",sizeof(A));
} |