implementation of polynimial class implementation
<p>i have following code to implement  ADT of polynimial class</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
using namespace std;
template&lt;class Number&gt;
class POLY
{
public:
    int n;
     Number *a;
public:
    POLY&lt;Number&gt;(Number c,int N){

        a=new Number[N+1];
          n=N+1;
            a[N]=c;
             for (int i=0;i&lt;N;i++) a[i]=0;
                }
    float eval( float x)  const {

         double t=0.0;
          for (int i=n-1;i&gt;=0;i--)
               t=t*x+a[i];
           return t;


    }


     friend POLY operator+(POLY &amp;p,POLY&amp;q){
        friend POLY operator+(POLY &amp;p,POLY&amp;q){

POLY t(0,p.n&gt;q.n?p.n-1:q.n-1);
           for (int i=0;i&lt;p.n;i++)
 t.a[i]+=p.a[i];
 for (int j=0;j&lt;q.n;j++)
   t.a[j]+=q.a[j];

   return t;

}



     }
     friend POLY operator+(POLY &amp;p,POLY&amp;q){



     }

}


int main(){






     return 0;
}
</code></pre>

<p>but    does  node work following pragment</p>

<pre><code>friend POLY operator+(POLY &amp;p,POLY&amp;q){

 POLY t(0,p.n&gt;q.n?p.n-1:q.n-1);
           for (int i=0;i&lt;p.n;i++)
 t.a[i]+=p.a[i];
 for (int j=0;j&lt;q.n;j++)
   t.a[j]+=q.a[j];

   return t;

}
</code></pre>

<p>it has problem with reference please tell me what is wrong?
errors</p>

<pre><code>1&gt;------ Build started: Project: polynomial, Configuration: Debug Win32 ------
1&gt;Build started 9/5/2010 6:00:34 PM.
1&gt;PrepareForBuild:
1&gt;  Creating directory "c:\users\david\documents\visual studio 2010\Projects\polynomial\Debug\".
1&gt;InitializeBuildStatus:
1&gt;  Creating "Debug\polynomial.unsuccessfulbuild" because "AlwaysCreate" was specified.
1&gt;ClCompile:
1&gt;  polynomial.cpp
1&gt;c:\users\david\documents\visual studio 2010\projects\polynomial\polynomial\polynomial.cpp(54): error C2143: syntax error : missing ';' before 'int'
1&gt;c:\users\david\documents\visual studio 2010\projects\polynomial\polynomial\polynomial.cpp(29): error C2270: '+' : modifiers not allowed on nonmember functions
1&gt;          c:\users\david\documents\visual studio 2010\projects\polynomial\polynomial\polynomial.cpp(54) : see reference to class template instantiation 'POLY&lt;Number&gt;' being compiled
1&gt;c:\users\david\documents\visual studio 2010\projects\polynomial\polynomial\polynomial.cpp(45): error C2270: '+' : modifiers not allowed on nonmember functions
1&gt;
1&gt;Build FAILED.
1&gt;
1&gt;Time Elapsed 00:00:01.36
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
</code></pre>

<p>i  have updated code</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ostream&gt;
using namespace std;

template&lt;class Number&gt;
class POLY
{
public:
    int n;
    Number *a;
public:
    POLY(Number c,int N){
        a=new Number[N+1];
        n=N+1;
        a[N]=c;
        for (int i=0;i&lt;N;i++) a[i]=0;
    }

    float eval( float x)  const {
        double t=0.0;
        for (int i=n-1;i&gt;=0;i--)
            t=t*x+a[i];
        return t;
    }

    friend POLY operator+(POLY &amp;p,POLY&amp;q){

        POLY t(0,p.n&gt;q.n?p.n-1:q.n-1);
        for (int i=0;i&lt;p.n;i++)
           t.a[i]+=p.a[i];
        for (int j=0;j&lt;q.n;j++)
           t.a[j]+=q.a[j];
        return t;
    }
     friend POLY operator*(POLY &amp;p,POLY &amp; q){

         POLY t(0,(p.n-1)+(q.n-1));
              for (int i=0;i&lt;p.n;i++)
                     for (int j=0;j&lt;q.n;j++)
                           t.a[i+j]=p.a[i] * q.a[j];
                return  t;

     }
};


int main(int argc,char *argv[]){
    float p=3.0f;
    int n=10;

    POLY&lt;int&gt; x(1, 1),one(1,0),t=x+one,y=t;
     for (int i=0;i&lt;n;i++)
     {  y=y*t;
     cout&lt;&lt;y&lt;&lt;endl;}
     cout&lt;&lt;y.eval(p)&lt;&lt;endl;

    return 0;
}
</code></pre>

<p>errors are</p>

<pre><code>&gt;c:\users\david\documents\visual studio 2010\projects\polynomial1\polynomial1\polynomial.cpp(55): error C2679: binary '&lt;&lt;' : no operator found which takes a right-hand operand of type 'POLY&lt;Number&gt;' (or there is no acceptable conversion)
1&gt;          with
1&gt;          [
1&gt;              Number=int
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;char,std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,const char *)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(726): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;char,std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,char)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(764): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,const char *)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(811): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,char)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(937): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,const signed char *)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(944): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,signed char)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(951): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,const unsigned char *)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(958): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,unsigned char)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(968): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;char,std::char_traits&lt;char&gt;,POLY&lt;Number&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;&amp;,_Ty)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;,
1&gt;              Number=int,
1&gt;              _Ty=POLY&lt;int&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::operator &lt;&lt;&lt;char,std::char_traits&lt;char&gt;&gt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,const std::error_code &amp;)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(186): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;(__cdecl *)(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;))'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(192): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(std::basic_ios&lt;_Elem,_Traits&gt; &amp;(__cdecl *)(std::basic_ios&lt;_Elem,_Traits&gt; &amp;))'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(199): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(std::ios_base &amp;(__cdecl *)(std::ios_base &amp;))'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(206): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(std::_Bool)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(226): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(short)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(260): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(unsigned short)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(280): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(int)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(305): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(unsigned int)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(325): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(long)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(345): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(unsigned long)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(366): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(__int64)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(386): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(unsigned __int64)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(407): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(float)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(427): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(double)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(447): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(long double)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(467): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(const void *)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          c:\program files\microsoft visual studio 10.0\vc\include\ostream(487): or       'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator &lt;&lt;(std::basic_streambuf&lt;_Elem,_Traits&gt; *)'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;
1&gt;          ]
1&gt;          while trying to match the argument list '(std::ostream, POLY&lt;Number&gt;)'
1&gt;          with
1&gt;          [
1&gt;              Number=int
1&gt;          ]
1&gt;
1&gt;Build FAILED.
1&gt;
1&gt;Time Elapsed 00:00:00.82
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
</code></pre>
