Identity Matrix error

Hi,

I am building an identity matrix as part of a matrix multiplication program. I made the code below and am getting an error "express must have arithmatic or unscoped enum type". Any suggestions as to why?

void identMatrix(double* identityMatrix[16])
{
int row[4];
int column[4];

for(row[4]=0, column[4]=0;row[4]<4, column[4]<4;row[4]++, column[4]++)
{
int index = row + (row*4); //The "row" in equation row*4 has the error
if (row == column)
identityMatrix[index] = 1;
else
identityMatrix[index] = 0;
}

cout << "Initializing identity matrix..." << endl;

}
It is the first time when I see such code.:)

for(row[4]=0, column[4]=0;row[4]<4, column[4]<4;row[4]++, column[4]++)

As for the error it means that row as an array used in expressions is converted to the pointer to its first element. There is no such operation for pointers as multiplication.
Last edited on
Why is "row" being converted to the pointer?
And how do you think I can fix it?


@nshogaboom
Why is "row" being converted to the pointer?


Because the developers of C/C++ decided that it is better to pass the pointer to the first element of array than copy all elements of the array when it is used in expressions, as argument and so on.

@nshogaboom
And how do you think I can fix it?


Your code in whole is wrong. For example you declared the array

int row[4];

This declaration means that the array has four elements that are indexed from 0 to 3. There is no such element as row[4] but you are trying to use it below in the code:

for(row[4]=0,

Topic archived. No new replies allowed.