title: How can I convert between types in a template and back to the original type
body: <p>I am wanting to make a template function that adds three numbers. The type may be int or char or string. How can I add these then return the correct value using the same type. Example: three strings of numbers {5,6,7} should add up to 18 then return 18 as a string. three chars of numbers {5,6,7} should add up to 18 then return 18 as a char.</p>
  
  <pre><code>template &lt;class MyType&gt;
  MyType GetSum (MyType a, MyType b, MyType c) {
    return (a+b+c);
  }
  
    int a = 5, b = 6, c = 7, d; 
    char e = '5', f = '6', g = '7', h; 
    string i= "5", j= "6", k= "7", l; 
  
    d=GetSum&lt;int&gt;(a,b,c);
    cout &lt;&lt; d &lt;&lt; endl;
  
    h=GetSum&lt;char&gt;(e,f,g);
    cout &lt;&lt; h &lt;&lt; endl;
  
    l=GetSum&lt;string&gt;(i,j,k);
    cout &lt;&lt; l &lt;&lt; endl;
  </code></pre>
  
  <p>This code works for int but obviously not for char or string. I am not sure how to convert from an unknown type to int and back so i can add the numbers.</p>