title: I need to convert class type array to template type. Can any one help me
body: <p><code>item[i]=static_cast&lt;T&gt;(the_list[i])</code>. This line is giving me an error stating </p>
  
  <blockquote>
    <p>[Error] invalid use of non-static data member 'SimpleVector::item'. </p>
  </blockquote>
  
  <p>I think the problem is with  typecasting. Now what can I do? </p>
  
  <pre><code>template &lt;class T&gt;
  
  class SimpleVector {
  
  public:
      SimpleVector();
      SimpleVector(int);
      SimpleVector(const SimpleVector &amp; copy);
      ~SimpleVector();
      friend istream &amp;operator&gt;&gt;( istream &amp;in, SimpleVector&lt;T&gt; &amp;the_list) 
      {
  
          for(int i=0;i&lt;the_list.size();i++)
          {
  
              in&gt;&gt;the_list[i];
              cout&lt;&lt;the_list[i];
              item[i]=static_cast&lt;T&gt;(the_list[i]);            
          }
          return in;
      }
      int size();
      T getElementAt(int n);
      T &amp; operator[](int index);
  
  private:
  
      T* item;
      int length;
  
  
  };
  </code></pre>
  
  <p></p>
  
  <pre><code>template&lt;typename T&gt;
  
  void doWork(int dataSize)
  {
      SimpleVector&lt;T&gt; list(dataSize);
      std::cout &lt;&lt; "Please enter the data:" &lt;&lt; std::endl;
      cin&gt;&gt;list; 
      int index;  
      SimpleVector&lt;T&gt; s;
      cout&lt;&lt;"Enter the index whose values you need to retrieve\n";
      cin&gt;&gt;index;
      cout&lt;&lt;s.getElementAt(index);   
  }
  
  
  
  
  
  int main()
  {
  
  int i,choice;
  
  cout&lt;&lt;"Enter the size of the array\n";
  cin&gt;&gt;i;
  cout&lt;&lt;"Type of data you need to enter\n";
  cout&lt;&lt;"Press 1 for int\n";
  cout&lt;&lt;"Press 2 for double\n";
  cout&lt;&lt;"Press 3 for string\n";
  cin&gt;&gt;choice;
  switch(choice)
  {
      case 1:
          doWork&lt;int&gt;(i);
          break;
      case 2:
          doWork&lt;double&gt;(i);
          break;
      case 3:
          doWork&lt;string&gt;(i);
          break;
  
  }
  
  
  return 0;
  }
  </code></pre>