Question on virtual inheritance

A

ambarish.mitra

#include <iostream>

class base {
public: virtual void f() {}
};

class derived: public virtual base {
};

int main()
{
std::cout << "size of base = " << sizeof(base) <<
std::endl; /* =4 . This is Okay.*/
std::cout << "size of derived = " << sizeof(derived) <<
std:endl; /* 4 or 8 */
}

In MS environment (Visual Studio 6/7), the output is coming as 8,
whereas in g++ compiler (g++ 3.4.5), the output is coming as 4.

Can any1 tell how the internals work out for virtual inheritance in
these 2 compilers? (I hv checked that size of pointer =4 in both
systems).
 
J

James Kanze

(e-mail address removed) wrote:

[...]
A pointer to the virtual base class subojbect is usually stored
in the class (just like a pointer to the virtual function table),


There are at least two different solutions: CFront stored a
pointer to the virtual base in the class, but other
implementations put the information necessary to do the fix-up
in the vtable. It's also possible to use thunks to do any
fixing up needed; these would also be in the vtable.

Beyond that, there are a number of variations possible in the
details, and as you said, the only way to find out is to ask in
a forum dedicated to the compiler in question, or to look it up
in the compiler's documentation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top