X
xkenneth
Hi,
I'm writing a sparse matrix class for class and I cannot seem to get
operator overloading to work properly.
I've overloaded an operator with the code here.
matrix operator +(matrix one, matrix other) {
cout << "adding" << endl;
return matrix(NULL,2,2); //doesn't actually carry out the operation,
but returns a different value, i'm just trying to test if it works
}
And i'm calling it with such a method:
matrix res(NULL,1,1);
res = *matrix1 + *matrix2; //this doesn't work
(*matrix1 + *matrix2).display() //this does? //it displays what i'm
looking for
res.display() //this displays the original value of res
With matrix1 and matrix2 of course being pointers to matrix objects.
Now, however after the call to the overloaded operator, res has the
same value, but when I call (*matrix1 + *matrix2) it displays the
added value i'm looking for. I can't quite understand for the life of
me why this value doesn't get assigned to the res variable.
Thanks for your time.
P.S. What's with all the spam on this newsgroup?
I'm writing a sparse matrix class for class and I cannot seem to get
operator overloading to work properly.
I've overloaded an operator with the code here.
matrix operator +(matrix one, matrix other) {
cout << "adding" << endl;
return matrix(NULL,2,2); //doesn't actually carry out the operation,
but returns a different value, i'm just trying to test if it works
}
And i'm calling it with such a method:
matrix res(NULL,1,1);
res = *matrix1 + *matrix2; //this doesn't work
(*matrix1 + *matrix2).display() //this does? //it displays what i'm
looking for
res.display() //this displays the original value of res
With matrix1 and matrix2 of course being pointers to matrix objects.
Now, however after the call to the overloaded operator, res has the
same value, but when I call (*matrix1 + *matrix2) it displays the
added value i'm looking for. I can't quite understand for the life of
me why this value doesn't get assigned to the res variable.
Thanks for your time.
P.S. What's with all the spam on this newsgroup?