Hi.
I recently wrote a matrix class and overloaded the '()' operator for easy access to the elements. I return the address of the selected element for easy modification.
Then I also thought that you might wanna make the element read-only, anyway this was my solution :
Code:
double & CMatrix::operator () (int row, int col)
{
//Err check omitted
if (readOnly)
{
double tempVal = elements[row][col];
return tempVal;
}
return elements[row][col];
}
I get a warning when I compile (returning address of local variable...) but I don't know if this would be bad/dangerous in this particular case.
Is this a bad way to do it in this case ? If so why, and what would be a better solution ?