I have a matrix2d class which consists of a dobule A[2][2]. I am trying to do a constructor which takes obejct of the same type and copies all its values to A[2][2]. I have a problem, here is the class:
class matrix2D {
public:
double A[2][2];
double Z[2][2];
//Default Constructor.
matrix2D() {
A[0][0] = A[1][1] = 1;
A[0][1] = A[1][0] = 0;
}
matrix2D(double x00,double x01, double x10, double x11) {
A[0][0] = x00;
A[0][1] = x01;
A[1][0] = x10;
A[1][1] = x11;
}
and now I am to create a constructor which takes matrix2D object and then takes all its values to A.
// Copy Constructor.
matrix2D(matrix2D& Z) {
for(int i = 0; i < 2; ++i) {
for(int j = 0; j < 2; ++j) {
A[i][j]=*(Z[i][j]);
}
}
}
It tells my that I try to assign double to matrix2d object. Why does *Z[i][j] does not reference to a double?
SOLVED: I did A[i][j]=Z.A[i][j] :)!
*? There is no pointer involved.Zas both a member variable of your class and as a constructor parameter. The compiler might give you a warning about that.