title: Share instance of base class for indirect base classes possible?
body: <p>I must admit I'm having trouble formulating this question, but I'll try my best to be precise. I have tried to search for an answer to my question, but I suspect I have been unable to find what I'm looking for, as I'm not exactly sure what to call this.</p>
  
  <p>I have a base class A, and several child classes inheriting from this base class. I then make another class X that inherits from some of the mentioned child classes. The problem I'm now facing is that each of the classes X inherits, have their own instance of class A. The code below should give a better understanding of what I mean.</p>
  
  <pre><code>class A;
  class B : public A;
  class C : public A;
  
  class X : public B, public C;
  </code></pre>
  
  <p>Is there a way to make class B and C share the same instance of class A, when they are both acting as indirect base classes for the same class? </p>
  
  <p>To give an example of why I want this, lets look at this code.</p>
  
  <pre><code>    class A
      {
          int _x;
      };
  
      class B : public A
      {
          void outputX(){std::cout &lt;&lt; A::_x &lt;&lt; std::endl;
      };
  
      class C : public A
      {
         void setX(int x){A::_x=x;}
      };
  
      class X : public B, public C
      {
          C::setX(5);
  
          // this will output an un-initialized _x, 
          // as B and C have their own version of A
          B::outputX() 
      };
  </code></pre>
  
  <p>Now I realize this seems rather unnecessary in this example here, but in my real situation I like to think it would be a good solution if B and C shared instance of A in class X.</p>
  
  <p>Is this at all possible?</p>