Thread View: gnu.g++
1 messages
1 total messages
Started by Gabriel Sanchez Gutierrez
Thu, 30 Nov 1989 15:20
A problem with = operator
Author: Gabriel Sanchez Gutierrez
Date: Thu, 30 Nov 1989 15:20
Date: Thu, 30 Nov 1989 15:20
79 lines
1946 bytes
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 .
*/
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads