title: Variant: no matching function for call to 'get'
body: <p>Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;variant&gt;
  #include &lt;vector&gt;
  
  class A {
  public:
      virtual void Foo() = 0;    
  };
  
  class B : public A {
  public:
      void Foo() override {
          std::cout &lt;&lt; "B::Foo()" &lt;&lt; std::endl;   
      }
  };
  
  class C :public A {
  public:
      void Foo() override {
          std::cout &lt;&lt; "C::Foo()" &lt;&lt; std::endl;   
      }
  };
  
  template&lt;typename... Args&gt;
  class D {
  public:
      template&lt;typename T&gt;
      void Foo() {
          m_variant = T{};
      }
  
      void Bar() {
        std::get&lt;m_variant.index()&gt;(m_variant).Foo();
      }
  
  private:
      std::variant&lt;std::monostate, Args...&gt; m_variant;
  };
  
  int main() {
      D&lt;B, C&gt; d;
      d.Foo&lt;B&gt;();
      d.Bar();
  
      d.Foo&lt;C&gt;();
      d.Bar();
  }
  </code></pre>
  
  <p>(c.f <a href="https://wandbox.org/permlink/mrryDZ4i7JWWdlCn" rel="nofollow noreferrer">wandbox.org</a>)</p>
  
  <p>I'm getting the error <code>no matching function for call to 'get'</code> but I don't figure out why. <code>std::variant::index()</code> is constexpr, so it isn't the problem (I tested by putting directly the value <code>1</code>, but still the same error).<br>
  I have a <code>std::monostate</code> to prevent an empty variant (when no args are in <code>typename... Args</code>)</p>