title: Call BaseState function instead of Derived function when using std::variant<...>
body: <p>I am experimenting with finate state machines and std::variant&lt;..&gt;</p>
  <p>std::variant will hold all possible states
  The states will be defined in State classes.</p>
  <p>What I wanted was to have a BaseState class, in which &quot;generic events&quot; should be handled.
  With derived State classes handling specific states.</p>
  <pre><code>struct LightOn;
  struct LightOff;
  
  struct Toggle;
  struct Reset;
  
  using State = std::variant&lt;LightOn,LightOff&gt;;
  using Event = std::variant&lt;Toggle,Reset&gt;;
  
  struct BaseState
  {
      void on_enter(){Serial.printf(&quot;BaseState enter\r\n&quot;);};
      void on_event (const Reset &amp;r);
  };
  
  struct LightOn : BaseState
  {
      LightOn(){Serial.printf(&quot;LightOn constructor\r\n&quot;);};
      void on_event(const Event &amp;e);
      void on_exit(){Serial.printf(&quot;LightOn exit\r\n&quot;);}
      void on_enter(){Serial.printf(&quot;LightOn enter\r\n&quot;);}
  };
  
  struct LightOff : BaseState
  {
      LightOff(){Serial.printf(&quot;LightOff constructor\r\n&quot;);};
      void on_event(const Event &amp;e);
      void on_exit(){Serial.printf(&quot;LightOff exit\r\n&quot;);}
  };
  
  struct Toggle
  {
      Toggle(){Serial.printf(&quot;Struct Toggle\r\n&quot;);};
  };
  
  struct Reset
  {
      Reset(){Serial.printf(&quot;Struct Reset\r\n&quot;);};
  };
  
  void LightOn::on_event(const Event &amp;e){Serial.printf(&quot;LightOn event\r\n&quot;);};
  void LightOff::on_event(const Event &amp;e){Serial.printf(&quot;LightOff event\r\n&quot;);};
  void BaseState::on_event(const Reset &amp;r){Serial.printf(&quot;BaseState reset\r\n&quot;);};
  </code></pre>
  <p>The question I have is in the <code>on_event</code> function.</p>
  <p>There is a specific one on Reset in the Basestate <code>void on_event(const Reset &amp;r);</code>
  And a more generic one in LightOn and LightOff <code>void on_event(const Event &amp;e);</code> (using Event = std::variant&lt;Toggle,Reset&gt;;)</p>
  <p>But when I do</p>
  <pre><code>LightOn n;
  n.on_event(Reset{}); 
  </code></pre>
  <p>The on_event from LightOn is called, not the one from BaseState.</p>
  <p>Is there a way to achieve : Call BaseState function when a BaseState function is available for this specific event ?</p>