title: Conditionally inheriting from either of two classes
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/11376149/generating-structures-dynamically-at-compile-time">Generating Structures dynamically at compile time</a>  </p>
  </blockquote>
  
  
  
  <p>I am now facing a situation where I want a derived class to inherit from either <code>Base1</code> or <code>Base2</code> depending on a condition (in C++03). This means, I want to implement something like:</p>
  
  <pre><code>// pseudo-C++ code
  class Derived : public
      if(condition) Base1    // inherit from Base1, if condition is true
      else Base2             // else inherit from Base2
  { /* */ };
  </code></pre>
  
  <p>This is likely not a good design, but the real world is not perfect. </p>
  
  <p>I have searched here for an answer, but I do not want to use a preprocessor directive <a href="https://stackoverflow.com/questions/7646820/problems-with-ifdef-based-inheritance-in-c">Problems with ifdef based inheritance in C++</a>.</p>
  
  <p>How else could I achieve this?</p>