title: How to construct a template that can call and return two different types
body: <p>I'm working on some code where I have two classes each with a method that returns said class with a specific value. Now these two class have different names and the methods which returns said class with a specific value have different names, however the value is the same. </p>
  
  <p>example</p>
  
  <pre><code>   class_a a = class_a::get_value_a()
     class_b b = class_b::get_value_b()
  
     a.value() == b.value() is true
  </code></pre>
  
  <p>Now what I'm trying to make is a generic way to get this value using template</p>
  
  <p>example</p>
  
  <pre><code>   class_generic g_a = class_generic::get_value&lt;class_a&gt;();
     class_generic g_b = class_generic::get_value&lt;class_b&gt;();
  
     g_a.value() == g_b.value() is true
  </code></pre>
  
  <p>But when making the template I tried to do the following</p>
  
  <pre><code>template &lt;typename T&gt; T class_generic::get_value()
  {
    if (typeid(T).hash_code() == typeid(class_a).hash_code())
    {
      return class_a::get_value_a()
    }
    if (typeid(T).hash_code() == typeid(class_b).hash_code())
    {
      return class_b::get_value_b();
    }
  }
  </code></pre>
  
  <p>But this will not compile and it seems to me that it tries to resolve both return types and converts one. </p>
  
  <p>So how do I do this correctly?</p>
  
  <p>regards</p>