virtual and sizeof

class A{
virtual void foo(){};
};sizeof(A)=1

class B : public virtural A{
virtual void foo(){};
};
sizeof(B)=? and why
Undefined by the standard, IIRC (even though the tutorial leads you to believe otherwise).



1
2
3
class A{
virtual void foo(){};
};sizeof(A)=1 //Why do you think sizeof A  will be 1   ?? 
sorry for my thoughtless, sizeof(A)=4.

Actually, I am confused by:
class C : public A{
virtual void foo(){};
};

how about sizeof(C)=?
what's the difference between B and C?
read
inside c++ object model

and clear all doubts.. :)
The difference between Class B and Class C is in the way they inherit from Class A.

class A

class B : public virtual A

class C : public A

The important bit is that word virtual it adds an extra virtual function pointer to Class B.
So you will probably find Class A is size 4, Class B is size 8 and Class C is size 4
guestgulkan,

I am afraid that sizeof(B)=4.
Compiler specific?

4 8 4 microsoft;
4 4 4 mingw_g++
Topic archived. No new replies allowed.