title: Virtual inheritance using empty classes
body: <p>Can anyone tell the exact reason for the output of the following code in C++ ?The output that I received for the  code is included in header comments. What does it have to do with virtual table and v pointer.</p>
  
  <pre><code>/* sizeof(Empty) 1                                                                                
   sizeof(Derived1) 1 
   sizeof(Derived2) 8 
   sizeof(Derived3) 1 
   sizeof(Derived4) 16 
   sizeof(Dummy) 1
  */
  
  #include &lt;iostream&gt;
  using namespace std;
  
  class Empty
  {};
  
  class Derived1 : public Empty
  {};
  
  class Derived2 : virtual public Empty
  {};
  
  class Derived3 : public Empty
  {    
  char c;
  };
  
  class Derived4 : virtual public Empty
  {
  char c;
  };
  
  class Dummy
  {
   char c;
  };
  
  int main()
  {
  
      cout &lt;&lt; "sizeof(Empty) " &lt;&lt; sizeof(Empty) &lt;&lt; endl;
      cout &lt;&lt; "sizeof(Derived1) " &lt;&lt; sizeof(Derived1) &lt;&lt; endl;
      cout &lt;&lt; "sizeof(Derived2) " &lt;&lt; sizeof(Derived2) &lt;&lt; endl;
      cout &lt;&lt; "sizeof(Derived3) " &lt;&lt; sizeof(Derived3) &lt;&lt; endl;
      cout &lt;&lt; "sizeof(Derived4) " &lt;&lt; sizeof(Derived4) &lt;&lt; endl;    
      cout &lt;&lt; "sizeof(Dummy) " &lt;&lt; sizeof(Dummy) &lt;&lt; endl;
      return 0;
  
  }
  </code></pre>