Oct 2, 2009 at 3:09pm UTC
in the definitions class I have .h file
TwoD operator =( const TwoD &r )
{
return ( *this = r);
}
IN THE PRIVATE SETION I HAVE A VARIABLE DIFINE
int ** eletwoD;
int x,y;
In .cpp file specifications file I have
TwoD& TwoD::operator =( const TwoD &r ) // overload assigment operator
{
if (x != r.x && y != r.y)
{
for(int i = 0; i < x; i++)
delete[] elewoD[i];
delete[eletwoD];
eletwoD = new int *[x]; // dynamically allocated array of int rows length
for( int i = 0; i < x+1; i++)
{
eletwoD[i] = new int[y]; // Fill the row up until max columns
}
}
x = r.x;
y = r.y;
for(int i = 0; i < x+1; i++)
{
eletwoD[i] = new int[x]; // Fill the row up til max columns
}
for ( int i = 0; i < x+ 1; i++ )
{
for ( int j = 0; j < y; j++ )
{
eletwoD[i][j] = r.eletwoD[i][j];
}
}
return *this;
}
Oct 2, 2009 at 3:16pm UTC
Does this even compile? It looks like you are overloading the assignment operator on return type only (which is illegal), and one of the instances looks infinitely recursive..
Oct 2, 2009 at 3:17pm UTC
Please use [co de][/code] tags.
Remove the body of operator = in the header. ie: TwoD &operator =( const TwoD &r );