How to eliminate a copy of variable in base class with multiple inheritance?
<p>As title describes, I have 3 classes:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

class first
{
protected :
 int data;
public :
 first() 
  :data( 1 )
 {
  // empty 
 }

};

class second : public first 
{
protected :
 double x;
public :
 second() 
  :first() 
 {
  // empty
 }
};

class combine : public first, public second
{
public :
 combine()
 {
  // empty
 }

};

int main()
{
 combine c;
 cout &lt;&lt; sizeof( c ) &lt;&lt; endl;

 return 0;
}
</code></pre>

<p>When I check the sizeof( first ) is 4 which make sense to me. But I don't know why sizeof( second ) is 16 ( I assumed 4 + 8 = 12 != 16 ), and sizeof( combine ) is 24 ( 4 + 4 + 8 = 16 != 24 ). Could anyone help me to explain this? 
Further, when '<strong>combine</strong>' multiple inherits from '<strong>first</strong>' and '<strong>second</strong>', I realized that its size includes both <strong>data</strong> ( int ) from '<strong>first</strong>' and '<strong>second</strong>' class; which is a waste of memory. Is there any way to work around this issue, i.e. let 'first' and 'second' share one copy of 'data'?</p>

<p>Best Regards,
Chan Nguyen</p>
