Question on virtual inheritance
  Home FAQ Contact Sign in
comp.lang.c++ only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c++ Profile…
 Up
Question on virtual inheritance         


Author: ambarish.mitra
Date: Apr 23, 2008 23:55

#include

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).
2 Comments
Re: Question on virtual inheritance         


Author: Victor Bazarov
Date: Apr 24, 2008 06:58

ambarish.mitra@gmail.com wrote:
> #include
>
> 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. ...
Show full article (1.52Kb)
no comments
Re: Question on virtual inheritance         


Author: James Kanze
Date: Apr 24, 2008 07:51

On Apr 24, 3:58 pm, "Victor Bazarov" comAcast.net> wrote:
> ambarish.mi...@gmail.com wrote:

[...]
> A pointer to the virtual base class subojbect[s] 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.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
no comments

RELATED THREADS
SubjectArticles qty Group
Quer sexo real, virtual? - It wants real, virtual sex?soc.culture.brazil ·