title: How to fix this class template
body: <p>I am trying to write a class, that in the simplest example works as follows:</p>
  
  <pre><code>// Example program
  #include &lt;iostream&gt;
  #include &lt;complex&gt;
  #include &lt;typeinfo&gt;
  
  template&lt;typename NumberType&gt;
  class SomeClass
  {
      public:
          SomeClass(NumberType a_) : a(a_) {}
          void get_number() 
          {
              if (typeid(NumberType) == typeid(std::complex&lt;double&gt;))
                  std::cout &lt;&lt; a.real() &lt;&lt; " " &lt;&lt; a.imag() &lt;&lt; std::endl;
              else
                  std::cout &lt;&lt; a &lt;&lt; std::endl;
          }
      private:
          NumberType a;
  };
  
  int main()
  {
      int a=1;
      std::complex&lt;double&gt; c(2.0,3);
  
      SomeClass&lt;int&gt; A(a);    
      A.get_number();
  
      SomeClass&lt;std::complex&lt;double&gt;&gt; C(c);
      C.get_number();
  
      return 0;
  }
  </code></pre>
  
  <p>It basically prints any real number as it is but it should split the complex number in two two reals.</p>
  
  <p>If I compile it as it is shown, the error message is as follows</p>
  
  <pre><code> In instantiation of 'void SomeClass&lt;NumberType&gt;::get_number() [with NumberType = int]':
  28:18:   required from here
  14:46: error: request for member 'imag' in '((SomeClass&lt;int&gt;*)this)-&gt;SomeClass&lt;int&gt;::a', which is of non-class type 'int'
  14:27: error: request for member 'real' in '((SomeClass&lt;int&gt;*)this)-&gt;SomeClass&lt;int&gt;::a', which is of non-class type 'int'
  </code></pre>
  
  <p>I understand that since <code>a</code> is of type <code>int</code> in the first case, I can not use <code>imag()</code> on it, hence the error message. </p>
  
  <p>How can I modify this class so that it does what I need in case of arbitrary <code>NumberType</code> template arguments?</p>