🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++
Article #219

A problem with = operator

#219
From: Gabriel Sanchez Gutierrez
Date: Thu, 30 Nov 1989 15:20
79 lines
1946 bytes
// 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 .

*/
Technical Details
Message-ID: <313@goya.dit.upm.es>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!goya!greco.dit.upm.es!gsanchez

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!goya!greco.dit.upm.es!gsanchez
From: gsanchez@greco.dit.upm.es (Gabriel Sanchez Gutierrez)
Newsgroups: gnu.g++
Subject: A problem with = operator
Message-ID: <313@goya.dit.upm.es>
Date: 30 Nov 89 15:20:43 GMT
Sender: newsadm@goya.dit.upm.es
Reply-To: gsanchez@greco.dit.upm.es (Gabriel Sanchez Gutierrez)
Organization: Dept. Ingenieria de Sistemas Telematicos, dit, upm, Madrid, Spain
Lines: 79