title: C++ Virtual Inheritance Memory Layout
body: <h3>Virtual Inheritance Memory Layouts</h3>
  
  <p>I am trying to fully understand what is happening under the hood in the memory with virtual inheritance and vTables/vPtrs and what not.</p>
  
  <p>I have two examples of code I have written and I understand exactly why they work however I just want to make sure I have the right idea in my mind, of the object memory layouts.</p>
  
  <p><a href="http://postimg.org/image/eyhxhc7g1/full/" rel="noreferrer">Here</a> are the two examples in a picture, and I just wish to know if my idea of the memory layouts involved are correct.</p>
  
  <p><strong>Example 1:</strong> </p>
  
  <pre><code>class Top { public: int a;  };
  class Left : public virtual Top {  public: int b; };
  class Right : public virtual Top { public: int c; };
  class Bottom : public Left, public Right { public:  int d; };
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/AASKM.jpg" alt="enter image description here"></p>
  
  <p><strong>Example 2:</strong> </p>
  
  <p>Same as above, but with: </p>
  
  <pre><code>class Right : public virtual Top {
  public:
      int c;
      int a;  // &lt;======= added this
  };
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/iJM7t.jpg" alt="enter image description here"></p>