title: std::variant of classes with same base class
body: <p>I'm not fully comprehending variants' usage, maybe someone can clear up what I'm doing wrong (possibly my approach).</p>
  
  <p>Let the variant object be _Types of two classes, both inheriting the same class.</p>
  
  <pre><code>class base
  {
  public:
      int foo;
  };
  class a: public base
  {
      int bar;
  };
  class b: public base
  {
      float bar;
  };
  
  byte variant_id = 0; // 0 for class A, 1 for class B
  std::variant&lt; base, a, b &gt; variant;
  </code></pre>
  
  <p>Here's how I use the variant:</p>
  
  <pre><code>void func( )
  {
      auto&amp; _variant = std::get&lt; base &gt;( variant ); // ideally would be = variant_id ? std::get&lt; b &gt;( variant ) : std::get&lt; a &gt;( variant )
      _variant.foo = 20;
  
      if ( variant_id == 1 )
      {
          auto&amp; variant_ = std::get&lt; b &gt;( variant );
          variant_.bar = 20.f;
      }
      else
      {
          auto&amp; variant_ = std::get&lt; a &gt;( variant );
          variant_.bar = 20;
      }
  </code></pre>
  
  <p>Maybe a union is more effective?</p>
  
  <pre><code>union
  {
      a _a;
      b _b;
  } variant;
  byte variant_id = 0;
  </code></pre>