Hi there,
I'm a new user of this forum and quite of a newbei in C/C++. I'd appreciate it if you could help me with one problem I'm having at the moment.
I've prepared a class to deal with matrices (yes, there are many of them around, but I found it a good exercise to learn all this staff). I've defined some methods with a * and + overloaded operators.
For example:
Most of the times it seems to ok. These expressions are correctly calculated (being A, B and C any of these class element):
A + B;
A + B + C;
A * B + C;
etc.
But when I start to mess with parenthesis, it seems to ignore parts of the expressions:
(A * B) + (A * C) would give the same result as just (A * B).
Do you have any idea why is this happening? Any suggestions?
Thank you very much in advance,
Guille
I'm a new user of this forum and quite of a newbei in C/C++. I'd appreciate it if you could help me with one problem I'm having at the moment.
I've prepared a class to deal with matrices (yes, there are many of them around, but I found it a good exercise to learn all this staff). I've defined some methods with a * and + overloaded operators.
For example:
Code:
Matrix& Matrix::operator* (Matrix& B) { Matrix A = *this; Matrix temp(nRow,nCol); for (int i=0; i<nRow; i++) for (int j=0; j<nCol; j++) for (int n=0; n<nRow; n++) temp(i,j) += A(i,n)*B(n,j); return temp; }
A + B;
A + B + C;
A * B + C;
etc.
But when I start to mess with parenthesis, it seems to ignore parts of the expressions:
(A * B) + (A * C) would give the same result as just (A * B).
Do you have any idea why is this happening? Any suggestions?
Thank you very much in advance,
Guille
Comment