title: C++, OOP, operator overloading errors?
body: <p>When I try using the <code>+</code> and <code>*</code>operators for both of my classes, I get errors.
  For overloading <code>+</code> I get: <code>Invalid operands of types nod* and nod* to binary operator+.</code>
  Same for <code>*</code>,and for the overloaded operators in my matrice class.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;cmath&gt;
  using namespace std;
  
  class nod
  {
      friend class matrice;
      float re,im;
      int i,j;
      nod *next;
      public:
      void setcomp(float x, float y)
      {
          re=x;
          im=y;
      }
      void setrand(int rand)
      {
          i=rand;
      }
      void setcol(int col)
      {
          j=col;
      }
      void setnext(nod *temp)
      {
          next=temp;
      }
      float getre()
      {
          return re;
      }
      float getim()
      {
          return im;
      }
      int getrand()
      {
          return i;
      }
      int getcol()
      {
          return j;
      }
      nod *getnext()
      {
          return next;
      }
      friend istream&amp; operator&gt;&gt;(istream &amp;in, nod *z);
      friend ostream&amp; operator&lt;&lt;(ostream &amp;out, nod *z);
      nod* operator+(nod *z);
      nod* operator*(nod *z);
      void operator=(nod *z);
  };
  
  istream&amp; operator&gt;&gt;(istream &amp;in, nod *z)
  {
      in&gt;&gt;z-&gt;re&gt;&gt;z-&gt;im;
      return in;
  }
  
  ostream&amp; operator&lt;&lt;(ostream &amp;out, nod *z)
  {
      if(z-&gt;im&lt;0)
      out&lt;&lt;z-&gt;re&lt;&lt;"-"&lt;&lt;z-&gt;im&lt;&lt;"i";
      else
      out&lt;&lt;z-&gt;re&lt;&lt;"+"&lt;&lt;z-&gt;im&lt;&lt;"i";
      return out;
  }
  
  nod* nod::operator+(nod *z)
  {
      nod *temp;
      temp-&gt;re=re+z-&gt;re;
      temp-&gt;im=im+z-&gt;im;
      return temp;
  }
  
  nod* nod::operator*(nod *z)
  {
      nod *temp;
      temp-&gt;re=(re*z-&gt;re)-(im*z-&gt;im);
      temp-&gt;im=(re*z-&gt;im)-(im*z-&gt;re);
      return temp;
  }
  
  void nod::operator=(nod *z)
  {
      re=z-&gt;re;
      im=z-&gt;im;
  }
  
  class matrice
  {
      nod *prim,*ultim;
      int n,m;
      public:
      matrice()
      {
          prim=NULL;
          ultim=prim;
      }
      int getl()
      {
          return n;
      }
      int getc()
      {
          return m;
      }
      nod* getprim()
      {
          return prim;
      }
      nod* getultim()
      {
          return ultim;
      }
      void adaugare(nod *p,int i,int j);
      void cautare1(nod *c, int i, int j);
      void cautare2(matrice a, nod *c, int i, int j);
      friend istream&amp; operator&gt;&gt;(istream &amp;in,matrice a);
      friend ostream&amp; operator&lt;&lt;(ostream &amp;out,matrice a);
      void afisare();
      matrice&amp; operator+(matrice b);
      matrice&amp; operator*(matrice b);
  }temp;
  
  void matrice::adaugare(nod *p,int i,int j)
  {
      if(prim==NULL)
          {
              prim = new nod;
              prim-&gt;re=p-&gt;re;
              prim-&gt;im=p-&gt;im;
              prim-&gt;setrand(i);
              prim-&gt;setcol(j);
              prim-&gt;setnext(NULL);
              ultim = prim;
          }
          else
          {
              nod* temp = new nod;
              temp-&gt;re=p-&gt;re;
              temp-&gt;im=p-&gt;im;
              temp-&gt;setrand(i);
              temp-&gt;setcol(j);
              temp-&gt;setnext(NULL);
              ultim-&gt;setnext(temp);
              ultim = temp;
          }
  }
  istream&amp; operator&gt;&gt;(istream&amp; in,matrice a)
  {
      float x,y;
      int i,j;
      nod *p;
      p=new nod;
      in&gt;&gt;a.n&gt;&gt;a.m;
      for(i=1;i&lt;=a.n;i++)
      {
          for(j=1;j&lt;=a.m;j++)
          {
              in&gt;&gt;p;
              a.adaugare(p,i,j);
          }
      }
      return in;
  }
  
  ostream&amp; operator&lt;&lt;(ostream &amp;out,matrice a)
  {
      nod *p=a.getprim();
      int i,j;
      for(i=1;i&lt;=a.n;i++)
      {
          for(j=1;j&lt;=a.m;j++)
          {
              out&lt;&lt;p;
          }
          out&lt;&lt;endl;
      }
      return out;
  }
  
  void matrice::cautare1(nod *c, int i, int j)
  {
      c=prim;
      while(c!=NULL)
      {
          if((c-&gt;getrand()==i)&amp;&amp;(c-&gt;getcol()==j))
          break;
          c=c-&gt;getnext();
      }
  }
  
  void cautare2(matrice a, nod *c, int i, int j)
  {
      c=a.getprim();
      while(c!=NULL)
      {
          if((c-&gt;getrand()==i)&amp;&amp;(c-&gt;getcol()==j))
          break;
          c=c-&gt;getnext();
      }
  }
  
  void matrice::afisare()
  {
      int i,j;
      nod *p=prim;
      for(i=1;i&lt;=n;i++)
      {
          for(j=1;j&lt;=m;j++)
          {
              cout&lt;&lt;p;
              p=prim-&gt;getnext();
          }
      }
  }
  
  matrice&amp; matrice::operator+(matrice b)
  {
      nod *prim2=b.prim;
      nod *p1=prim, *p2=prim2, *ps;
      ps=new nod;
      int i,j;
      matrice s;
      for(i=1;i&lt;=n;i++)
      {
          for(j=1;j&lt;=m;j++)
          {
              ps=p1+p2;
              s.adaugare(ps,i,j);
              p1=p1-&gt;getnext();
              p2=p2-&gt;getnext();
          }
      }
      return s;
  }
  
  matrice&amp; matrice::operator *(matrice b)
  {
      matrice p;
      nod *p1=new nod,*p2=new nod,*q=new nod;
      int i,j,k;
      for(i=1;i&lt;=n;i++)
      {
          for(j=1;j&lt;=b.m;j++)
          {
              q-&gt;setcomp(0,0);
              q-&gt;setrand(i);
              q-&gt;setcol(j);
              p.adaugare(q,i,j);
          }
      }
      for(i=1;i&lt;=n;i++)
      {
          for(j=1;j&lt;=b.m;j++)
          {
              for(k=1;k&lt;=m;k++)
              {
                  cautare2(p,q,i,j);
                  cautare1(p1,i,k);
                  cautare2(b,p2,k,j);
                  q=p1*p2;
              }
          }
      }
      return p;
  }
  
  void submat(matrice a, matrice &amp;b,int n, int x, int y)
  {
      int i,j,k=0;
      nod *q;
      for(i=1;i&lt;=n;i++)
          for(j=1;j&lt;=n;j++)
              if((i!=x)&amp;&amp;(j!=y))
              {
                  k++;
                  if(k==n)
                  {
                      k=1;
                      x++;
                  }
                  cautare2(a,q,i,j);
                  b.adaugare(q,x,k);
  
              }
  }
  
  nod *determinant(matrice a,int n)
  {
      matrice b;
      nod *temp,*c,*d,*oarecare,*p1,*p2,*p3,*p4;
      int i;
      float real,imag,real2,imag2;
      temp=new nod;
      temp-&gt;setcomp(0.0,0.0);
      temp-&gt;setrand(0);
      temp-&gt;setcol(0);
      if(n==1)
      {
          cautare2(a,oarecare,1,1);
          temp-&gt;setcomp(oarecare-&gt;getre(),oarecare-&gt;getim());
      }
      else
      {
          if(n==2)
          {
              cautare2(a,p1,1,1);
              cautare2(a,p2,2,2);
              temp=p1*p2;
              cautare2(a,p3,1,2);
              cautare2(a,p4,2,1);
              temp=temp-p3*p4;
          }
              else
              {
                  for(i=1;i&lt;=n;i++)
                  {
                      submat(a,b,n,1,i);
                      c-&gt;setcomp(pow(-1,i+1),0);
                      c-&gt;setrand(0);
                      c-&gt;setcol(0);
                      cautare2(a,p1,1,i);
                      c=c*p1;
                      d=temp;
                      c=c*determinant(b,n-1);
                      temp=d+c;
                  }
              }
      }
      return temp;
  }
  
  void inversa(matrice a, nod *&amp;z)
  {
      nod *p1,*p2,*temp,*y;
      matrice b,tr,c;
      int i,j,n;
      n=(a.getultim())-&gt;getrand();
      float real, imag;
      for(i=1;i&lt;=n;i++)
      {
          for(j=1;j&lt;=n;j++)
          {
              cautare2(a,p1,j,i);
              tr.adaugare(p1,i,j);
          }
      }
      for(i=1;i&lt;=n;i++)
      {
          for(j=1;j&lt;=n;j++)
          {
              submat(tr,b,n,i,j);
              y-&gt;setcomp(pow(-1,i+j),0);
              c.adaugare(y,i,j);
              temp=determinant(b,n-1);
              cautare2(c,p2,i,j);
              p2=p2*temp;
              real=z-&gt;getre()/(pow(z-&gt;getre(),2)+pow(z-&gt;getim(),2));
              imag=z-&gt;getim()/(pow(z-&gt;getre(),2)+pow(z-&gt;getim(),2));
              temp-&gt;setcomp(real, imag);
              p2=p2*temp;
          }
      }
      c.afisare();
  }
  
  int main()
  {
      ifstream f("mat.txt");
      matrice a,b;
      f&gt;&gt;a&gt;&gt;b;
      cout&lt;&lt;"Matricea A:\n"&lt;&lt;a;
      cout&lt;&lt;"\nMatricea B:\n"&lt;&lt;b;
      cout&lt;&lt;a+b;
      return 0;
  }
  </code></pre>