Answer the question
In order to leave comments, you need to log in
How to overload operator * for own class?
matrix.hpp
class Matrix
{
public:
Matrix(int rows, int columns, const double* elems);
~Matrix();
Matrix* operator*(Matrix& matrix);
double det();
Matrix* invert();
Matrix* transpose();
};
Matrix* Matrix::operator*(Matrix& matrix)
{
//
}
int main(int argc, char** argv)
{
double d[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
Matrix* m = new Matrix(3, 3, d);
Matrix* m1 = new Matrix(3, 3, d);
Matrix* m2 = m * m1;
return EXIT_SUCCESS;
}
Answer the question
In order to leave comments, you need to log in
You are trying to multiply pointers. Dereference them first.
Or make the operator not a member of the class, with the signature (Matrix*, Matrix*).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question