title: How to use template function to set values with different types?
body: <p>everyone!</p>
  
  <p>I have a template function named UpdateValue, which was designed to update some values with different types such as integer, BOOL, string, and so on. Please see the following code snippet for your reference:</p>
  
  <pre><code>#include &lt;typeinfo.h&gt;
  
  template&lt;class T&gt; 
  void UpdateValue(T Value)
  {   
      if ( typeid(int) == typeid(Value) ) 
      {  
         ZOrder(Value);
      }
      else if ( typeid(bool) == typeid(Value) )
      {  
         BOOL bShow = Value ? TRUE : FALSE;
         Show(bShow);
      }
      else if ( typeid(CString) == typeid(Value) )
      {  
         Theme(Value);
      }
  }
  
  void Show(BOOL bShow) { m_bShow = bShow; }
  void ZOrder(int nZOrder) { m_nZOrder = nZOrder; }
  void Theme(CString strTheme) { m_strTheme = strTheme; }
  
  BOOL m_bShow;
  int m_nZOrder;
  CString m_strTheme;
  </code></pre>
  
  <p>But when I use the following statements to call this kind of template function</p>
  
  <pre><code>CString strValue = _T("Animal");
  UpdateValue&lt;CString&gt;(strValue);
  </code></pre>
  
  <p>the aforesaid code failed to compile by throwing the following exceptions:</p>
  
  <blockquote>
    <p>e:\dynaprop\dynaprop\mainfrm.cpp(269) : error C2664: 'CMainFrame::ZOrder' : cannot convert parameter 1 from 'CString' to 'int'
    1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>        e:\dynaprop\dynaprop\mainfrm.cpp(67) : see reference to function template instantiation 'void CMainFrame::UpdateValue(T)' being compiled
    1>        with
    1>        [
    1>            T=CString
    1>        ]  </p>
  </blockquote>
  
  <p>Would you please show me how to figure it out? Thank you in advance!</p>