help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Virtual inheritance and vtables?


From: Samuli
Subject: Virtual inheritance and vtables?
Date: Sun, 14 Oct 2007 16:41:38 +0300 (EEST)
User-agent: slrn/0.9.8.1pl1 (SunOS)

This program


#include <iostream>

using std::cout;
using std::endl;

class A {int a;};

class B : public virtual A{};

int main(){
  cout << "sizeof B is " << sizeof(B) << endl;
  return 0;
}


produces following output:

sizeof B is 8

Why?

There are no virtual functions, so I thought there would be no
extra pointers (to vtable) needed either. But it doesn't seem to 
play out that way. 
What information does that pointer point to? Why is it neccesary? 
Can I avoid the generation of that extra pointer somehow, while still 
using virtual base classes?

-Samuli


reply via email to

[Prev in Thread] Current Thread [Next in Thread]