title: How to access a class variable in a std::vector?
body: <p>I have a vector consisting of a variation of classes, and I am trying to access a variable found in the classes. For example:</p>
  <pre><code>class MyClass1
  {
  public:
      int variable = 5;
  };
  
  std::vector&lt;std::variant&lt;MyClass1, MyClass2, MyClass3&gt;&gt; data;
  
  data[0].emplace&lt;MyClass2&gt;();
  ...
  data[5].emplace&lt;MyClass1&gt;(); // initialising 
  
  std::cout &lt;&lt; data[5].variable &lt;&lt; std::endl;
  </code></pre>
  <p>Expected output:</p>
  <pre><code>5
  </code></pre>