title: Virtual inheritance with abstract middle class
body: <p>This isn't a question about how to do something, I know well about virtual inheritance, and I know of a few ways to circumvent this problem - but none that I am happy about.</p>
  
  <p>Here is some code that doesn't compile:</p>
  
  <pre><code>struct BottomClass
  {
      BottomClass(int&amp; ref) : ref(ref) {}
      int&amp; ref;
  };
  
  struct MiddleClassA : virtual public BottomClass
  {
      MiddleClassA() /*: BottomClass()*/ {}
      virtual ~MiddleClassA() = 0;
  };
  
  MiddleClassA::~MiddleClassA(){}
  
  struct MiddleClassB : virtual public BottomClass
  {
      MiddleClassB() /*: BottomClass()*/ {}
      virtual ~MiddleClassB() = 0;
  };
  
  MiddleClassB::~MiddleClassB(){}
  
  struct TopClass final : public MiddleClassA, public MiddleClassB
  {
      TopClass(int&amp; ref) : BottomClass(ref) {}
  };
  
  void main()
  {
      int someInt;
      TopClass variable(someInt);
  }
  </code></pre>
  
  <p>What bothers me is why this doesn't compile. I know that there is no default constructor for BottomClass and hence MiddleClassX is ill-formed. But MiddleClassX are abstract classes! Even if I specified a constructor there it wouldn't be used under any circumstances... so why should I specify that?</p>
  
  <p>I couldn't even give a sensible constructor there because MiddleClassX doesn't have any reasonable value to give to the BottomClass.</p>
  
  <p>My question is: is there an elegant solution to this problem?</p>
  
  <hr>
  
  <p>I have a few solutions myself, but I don't like any of them especially:</p>
  
  <p>1) I could create a BottomClass default constructor that uses some garbage value to construct its ref. And then assert() in that constructor so I know it is never called... Of course this leads to me having to do run-time checking of everything that should be a compile-time error, and it also practically demands the existence of a garbage integer to get the reference of.</p>
  
  <p>2) I could pass the reference to every abstract middle class and use that... But this leads to serious repetition of information, and when these chains get long (as they do) it is very tedious to maintain that. There is also the performance hit of having to pass an extra variable to every class.</p>
  
  <p>(I apologize if my question is hard to understand - if anyone can better describe my dilemma that would be awesome, I'm challenged to put this into words)</p>