title: Base class needs to return auto-type based on derived specific type
body: <p>I would like to make a generic base class for storing the same Interface class in an array. However, the generic class should return a type specific variable based on its derivative.</p>
  
  <p>I tried different design approaches with templates and type deductions... Also tried to store the actual value in a nested class container.</p>
  
  <p>I think, I need a different approach instead of solving this... But I don't know what will work for me.
  Any designed patterns that can tackle this approach ?</p>
  
  <p>Base Class</p>
  
  <pre><code>class IAlpha
  {
  public:
      virtual auto Get() = 0;
  };
  </code></pre>
  
  <p>Derived Class</p>
  
  <pre><code>template&lt; typename T &gt;
  class Alpha:
      public IAlpha
  {
      T x;
  public:
      Alpha( T _x ):x(_x)
      {
  
      }
  
      auto Get() -&gt;decltype(x) override
      {
          return x;
      }
  };
  </code></pre>
  
  <p>Main</p>
  
  <pre><code>    IAlpha *i = new Alpha&lt;int&gt;(1);
      IAlpha *d = new Alpha&lt;double&gt;(1.0);
  
  
      int x = i-&gt;Get();
      double y = d-&gt;Get();
  </code></pre>
  
  <p>The error I get at IAlpha::Get()
  "Function with deduced return type cannot be virtual"</p>
  
  <p>I understand the problem, and it can be resolved for example by</p>
  
  <pre><code>virtual auto Get()-&gt;decltype(  "TYPE"  ) = 0;
  </code></pre>
  
  <p>But the problem is the Interface does not know the TYPE and it should not to maintain it generic....</p>
  
  <p>Note,
  <code>std::variant</code> &amp; <code>std::any</code> are unfortunately no options in my application.</p>