explanation!!

class matrice {
double *tab;
unsigned lgn, col;
public:

matrice& operator=(matrice& m)
{
lgn = m.lgn; col = m.col;
tab = new double[lgn*col];
return *this;
}
};

Can you explain me the role of this 3 lines:
lgn = m.lgn; col = m.col;
tab = new double[lgn*col];
return *this;
lgn = m.lgn;This sets the value of the class member variable lgn equal to the value m.lgn

col = m.col;This sets the value of the class member variable col equal to the value m.col

tab = new double[lgn*col]; This sets the value of the pointer tab equal to the value of the pointer returned by the call to new.

Do you really need us explain this to you? This is a copy constructor. It explains to the compiler how to make a copy of an object of type matrice.

It doesn't seem to be finished, as it doesn't copy the actual contents of the matrice; it just makes a new matrice of the same dimension.
Last edited on
Topic archived. No new replies allowed.