title: how to determine sizeof class with virtual functions?
body: <p>this is kind of homework question. For the following code,</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class A
  {
  public:
      virtual void f(){}
  };
  
  class B
  {
  public:
      virtual void f2(){}
  };
  
  class C: public A, public B
  {
  public: 
      virtual void f3(){}
  };
  
  class D: public C
  {
  public:
      virtual void f4(){}
  };
  
  int main()
  {
      cout&lt;&lt;sizeof(D)&lt;&lt;endl;
  }
  </code></pre>
  
  <p><strong>The output is: 8</strong></p>
  
  <p>Could anyone please explain how it is 8 bytes? If the vtable implementation is compiler dependent, what should I answer for this kind of question in interviews? What about virtual base classes?</p>
  
  <p>EDIT: i am working on a 32-bit platform.</p>