[gnu.g++] A problem with = operator

gsanchez@greco.dit.upm.es (Gabriel Sanchez Gutierrez) (11/30/89)

// I am a new C++ programmer and I have a little (??) problem with
// the operator = .

// I want to do a pointers chain . When I want to do a assignment between
// pointers , the compiler finds the = operator for the object ( I think ,
// but I am not a expert ) .

//  This is the code :

#include <stdio.h>

class T
{
   int t ;
   T* next ;
 public :
   T(int) ;
   ~T()   ;    // His contenst

   void print1(void);
   T& operator = (T&) ;
};


T::T ( int val )
{
  t = val ;
  if (--val)
       next = new T (val);
  else
       next = 0;
}



T& T::operator= (T& tt)
{
   return (*this);     // It's enough for this test .
}


void T::print1(void)
{
  T* other = this ;

  printf("\n\n");
  do
    printf("%d ",other->t);
  while (other=other->next);
}


/****

   In three lines , it gives errors :

     >> Constructor : next = new T (val) 
                      next = 0 
     >> print1      : other = other->sigo

   He tells me to miss parameters for the constructor . The errors are


 In method T::T (int):
   25: bad argument list for method `operator ='
   27: bad argument list for method `operator ='
 In method T::print1 ():
   45: bad argument list for method `operator ='

   I want to do an assignment between pointer to T , not between
  objects of type T .

   Do I forget something important ?
   Is my error a basic error ?

 Thanks . A beginner .

*/