title: Not being able to store a variant in a pointer in c++
body: <p>My groupmate and I are doing a school assignment and we are having some trouble trying to save a value.
  I am 100% aware that some of the things done in the code is not the normal way of doing, and that there are better ways, but part of the assignment is to use the concepts taught in class.</p>
  <p>Problem:</p>
  <p>I have a Train class which I would like to assign to a platform, such that I know if there is a train on the platform.</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  class Train
  {
  public:
      //Some constructors, getters and other stuff 
  private:
      std::string reg_nr_;
  }
  </code></pre>
  <p>Because the Train is a template there are different template argument classes so it is possible to give it a type</p>
  <pre class="lang-cpp prettyprint-override"><code>struct IC3{};
  
  struct IC4{};
  </code></pre>
  <p>To instantiate a Train it is done in main in the following way, as is the way it is intended to be used.</p>
  <pre class="lang-cpp prettyprint-override"><code>Train&lt;IC3&gt; tester_train(&quot;testing_train&quot;);
  Train&lt;IC4&gt; some_other_tester_train(&quot;some_other_tester_train&quot;);
  
  Platform pl;
  pl.train_arriving(tester_train);
  pl.train_leaving(tester_train);
  pl.train_arriving(some_other_tester_train);
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>class Platform
  {
  public:
      using Trains = std::variant&lt;TrainWrapper&lt;Train&lt;Arriva&gt;&gt;, TrainWrapper&lt;Train&lt;IC3&gt;&gt;, TrainWrapper&lt;Train&lt;IC4&gt;&gt;&gt;;
  
      template&lt;typename U&gt;
      void train_arriving(U&amp; t)
      {
          train_ = TrainWrapper&lt;U&gt;{ u };
      }
  
      void train_leaving()
      {
          train_ = ???????; //Should be set to nothing
      }
  private:
      Trains train_;
  }
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  struct TrainWrapper
  {
      T&amp; t;
  };
  </code></pre>
  <p>Now for the real part of the problem.
  I have a Train template class which takes an argument and transform the Train in different types which are not compatible. This presents a problem of being able to pass these different train types into the platform and saving them.
  To solve the problem of different passing in different types a std::variant has been used. This presented a new problem of not being able to retrieve the data easily, which is why the TrainWrapper is used, such that the Train is stored in a common type.</p>
  <p>Tinkering around with the variant (and finally asking our teacher) my groupmate and I arrived <code>Trains</code> expression seen in Platform. We know for a fact (using a local variable) that we are able to save a TrainWrapper in a Trains object. Our problem however is that we would like to be able to change the Train on the Platform. We therefore thought a pointer would be the way forward, but doing this we run into conversion errors like: <code>Error    C2440   '=': cannot convert from 'TrainWrapper&lt;Train&lt;Arriva&gt;&gt;' to 'Platform::Trains *'</code>. We have tried a bunch of different pointer variations, but it is always the same conversion error.</p>
  <p>So our question more or less is: How are we able to save Train on the platform so we are able to remove it again?</p>