D
Dave
Hi there:
i am doing a matrix class for practice. everything is ok except the []
operator. Basically, i want to achieve the same way as the normal
double[]'s, such as:
m[2][3] = 4.0;
m[3][4] = m[4][5] + m[2][3];
cout<<m[2][3]<<endl;
I also want the indices to be 1 based instead of 0 based.
One way I can think out is to have the following overloaded operator
in matrix class:
double* operator [] (int row_index); suppose the matrix contains
doubles and i am using a double pointer to store the numbers.
but I have the following problems with this approach:
1. the second index can't be 1 based since it's used to directly
indexed into the double*. It has to be 0 based.
2. it's not safe. since the function returns the row pointer. the
caller can just call m[2] and then do some bad things.
but that's the only way I can think out now. Is there a good way to
solve this problem?
Thanks a lot.
i am doing a matrix class for practice. everything is ok except the []
operator. Basically, i want to achieve the same way as the normal
double[]'s, such as:
m[2][3] = 4.0;
m[3][4] = m[4][5] + m[2][3];
cout<<m[2][3]<<endl;
I also want the indices to be 1 based instead of 0 based.
One way I can think out is to have the following overloaded operator
in matrix class:
double* operator [] (int row_index); suppose the matrix contains
doubles and i am using a double pointer to store the numbers.
but I have the following problems with this approach:
1. the second index can't be 1 based since it's used to directly
indexed into the double*. It has to be 0 based.
2. it's not safe. since the function returns the row pointer. the
caller can just call m[2] and then do some bad things.
but that's the only way I can think out now. Is there a good way to
solve this problem?
Thanks a lot.