title: What is wrong with this template program?
body: <p>I've been trying to learn templates in C++ but I'm getting a little confused with what I'm doing wrong. I was told how to declare friend templates on a FAQ about templates and I had to do that with the overloaded operators but it seems to be giving me trouble telling me I have an invalid amount of arguments(I should have 2) in my Array.cpp. Is there any way I could fix this while keeping my operators. Also, is the simple main file the correct syntax for the templates?</p>
  
  <p>Thank you.</p>
  
  <p>Array.h:</p>
  
  <pre><code>#ifndef ARRAY_H
  #define ARRAY_H
  #include &lt;stdexcept&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  template&lt;typename T&gt; class Array;
  template&lt;typename T&gt; ostream &amp;operator&lt;&lt;( ostream &amp;, const Array&lt;T&gt; &amp; );
  template&lt;typename T&gt; istream &amp;operator&gt;&gt;( istream &amp;, Array&lt;T&gt; &amp; );
  
  template&lt; typename T &gt;
  class Array
  {
  
  
      friend ostream &amp;operator&lt;&lt; &lt;&gt; ( ostream &amp;, const Array&lt;T&gt; &amp; );
      friend istream &amp;operator&gt;&gt; &lt;&gt; ( istream &amp;, Array&lt;T&gt; &amp; );
  
   public:
      Array(  int = 10 ); 
  
      Array( const Array &amp; ); 
  
      ~Array();
  
      int getSize() const; 
  
      const Array &amp;operator=( const Array &amp; ); 
  
      bool operator==( const Array &amp; ) const; 
  
  
      bool operator!=( const Array &amp;right ) const  
      { 
          return ! ( *this == right ); 
      }
  
  
      T &amp;operator[]( T );              
  
  
      T operator[]( T ) const;  
  
   private:
  
      int size; 
  
      T *ptr;
  
  };
  
  #endif
  </code></pre>
  
  <p>Array.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cstdlib&gt; // exit function prototype
  #include "Array.h" // Array class definition
  using namespace std;
  
  template&lt; typename T &gt;
  Array&lt;T&gt;::Array( int arraySize )
  {
  
      if ( arraySize &gt; 0 )
          size = arraySize;
      else 
          throw invalid_argument( "Array size must be greater than 0" );
  
      ptr = new T[ size ]; 
  
      for ( int i = 0; i &lt; size; ++i )
          ptr[ i ] = 0;
  
  }
  
  template&lt; typename T &gt;
  Array&lt;T&gt;::Array( const Array &amp;arrayToCopy ) 
     : size( arrayToCopy.size )
  {
      ptr = new T[ size ];
  
      for ( int i = 0; i &lt; size; ++i )
          ptr[ i ] = arrayToCopy.ptr[ i ];
  }
  
  template&lt; typename T &gt;
  Array&lt;T&gt;::~Array()
  {
      delete [] ptr; 
  }
  
  template&lt; typename T &gt;
  int Array&lt;T&gt;::getSize() const
  {
      return size;
  }
  
  template&lt; typename T &gt;
  const Array&lt;T&gt; &amp;Array&lt;T&gt;::operator=( const Array &amp;right )
  {
      if ( &amp;right != this )
          {
  
              if ( size != right.size )
                  {
                      delete [] ptr;
                      size = right.size; 
                      ptr = new T[ size ]; 
                  }
  
              for ( int i = 0; i &lt; size; ++i )
                  ptr[ i ] = right.ptr[ i ]; 
          }
  
      return *this;
  }
  
  template&lt; typename T &gt;
  bool Array&lt;T&gt;::operator==( const Array &amp;right ) const
  {
      if ( size != right.size )
          return false;
  
      for ( int i = 0; i &lt; size; ++i )
          if ( ptr[ i ] != right.ptr[ i ] )
              return false; 
  
     return true; 
  }
  
  template&lt; typename T &gt;
  T &amp;Array&lt;T&gt;::operator[]( T subscript )
  {
  
      if ( subscript &lt; 0 || subscript &gt;= size )
          throw out_of_range( "Subscript out of range" );
  
      return ptr[ subscript ];
  }
  
  template&lt; typename T &gt;
  T Array&lt;T&gt;::operator[]( T subscript ) const
  {
  
      if ( subscript &lt; 0 || subscript &gt;= size )
          throw out_of_range( "Subscript out of range" );
  
      return ptr[ subscript ]; 
  }
  
  // overloaded input operator for class Array;
  // inputs values for entire Array
  
  template&lt; typename T &gt;
  istream &amp;Array&lt;T&gt;::operator&gt;&gt;( istream &amp;input, Array &amp;a )
  {
      for ( int i = 0; i &lt; a.size; ++i )
          input &gt;&gt; a.ptr[ i ];
  
      return input; // enables cin &gt;&gt; x &gt;&gt; y;
  } // end function 
  
  // overloaded output operator for class Array
  template&lt; typename T&gt; 
  ostream &amp;Array&lt;T&gt;::operator&lt;&lt;( ostream &amp;output, const Array &amp;a )
  {
      int i;
  
      // output private ptr-based array 
      for ( i = 0; i &lt; a.size; ++i )
          {
              output &lt;&lt; setw( 12 ) &lt;&lt; a.ptr[ i ];
  
              if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output
                  output &lt;&lt; endl;
          } // end for
  
      if ( i % 4 != 0 ) // end last line of output
          output &lt;&lt; endl;
      return output; // enables cout &lt;&lt; x &lt;&lt; y;
  } // end function operator&lt;&lt;
  </code></pre>
  
  <p>My main file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include "Array.h"
  
  using namespace std;
  
  
  int main()
  
  {
  
      Array&lt;int&gt; integers1( 7 ); // seven-element Array
  
      Array&lt;int&gt; integers2; // 10-element Array by default
  
  
  
      // print integers1 size and contents
  
      cout &lt;&lt; "Size of Array integers1 is "
  
           &lt;&lt; integers1.getSize()
  
           &lt;&lt; "\nArray after initialization:\n" &lt;&lt; integers1;
  
  }
  </code></pre>