Mail Archives: djgpp/1997/08/03/21:35:22
Timothy Robb wrote:
> I'm trying to get a 2d matrix class to work which seems to compile fine
> but crashes whenever I try to access data elements.
I took a quick scan, and immediately came across a fundamental problem (I
stopped looking there; there may be more). The problem is in
Matrix::Matrix:
data = new Complex* [rows];
assert(data != NULL);
for(int i=0; i<rows; i++);
{
data[rows] = new Complex[columns];
assert(data[rows] != NULL);
}
There are two serious problems here. First, there's a semicolon after the
for statement, which means that you have a null for loop.
The second is that, even if the semicolon weren't there, you're accessing
the data array with data[rows], which is not only wrong (you meant
data[i]), but also will crash, because it exceeds the bounds of the array
(which has rows elements, from 0 .. rows - 1).
--
Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com
Alcyone Systems / web / http://www.alcyone.com/max/
San Jose, California, United States / icbm / 37 20 07 N 121 53 38 W
\
"Love is not love which alters / when it alternation finds."
/ William Shakespeare, _Sonnets_, 116
- Raw text -