title: Multiple inheritance and the this pointer
body: <p>Suppose I have this struct:</p>
  
  <pre><code>struct vector_data
  {
      double x, y;
  
      double&amp; operator[](size_t index)
      {
          return * (static_cast&lt;double*&gt;(static_cast&lt;void*&gt;(this)) + index);
      }
  };
  </code></pre>
  
  <p>The operator[] should work as expected, because vector_data is a POD type.
  The expected behaviour is that vector_data[0] returns x, and vector_data[1] returns y.</p>
  
  <p>Now suppose I have a second struct:</p>
  
  <pre><code>struct more_data
  {
      double evil_data;
  
      // There could be more here, data or functions
  };
  </code></pre>
  
  <p>And derive from both like this:</p>
  
  <pre><code>struct composed : public more_data, public vector_data
  {
  };
  </code></pre>
  
  <p>Will this destory the expected behaviour of operator[]? In other words, will the this-pointer of vector_data in the derived struct still point to the vector_data part of the struct, or will it point to the beginning of the derived struct?</p>
  
  <p>If it does destroy operator[], then how can I resolve this problem? I can inherit from vector_data first, but suppose composed contains virtual functions. I know most compilers put the vtable at the end, but this is not guaranteed. What would be the best approach?</p>