I have a collect2 error (as in the title) when I try to test this code to get the inverse or print the matrix. Any suggestions ? Thank you
So here's my header file and below you can find the implementation file and the main function
#ifndef SUBMISSION_MATRIX2X2_HPP_
#define SUBMISSION_MATRIX2X2_HPP_
#include <iostream>
class Matrix2x2 {
private:
double val00; // first row, first column
double val01; // first row, second column
double val10; // second row, first colum
double val11; // second row, second column
public:
Matrix2x2();
Matrix2x2(const Matrix2x2& other);
Matrix2x2(double a, double b, double c, double d);
double CalcDeterminant() const;
Matrix2x2 CalcInverse() const;
Matrix2x2& operator=(const Matrix2x2& z);
Matrix2x2 operator-() const;
Matrix2x2 operator+(const Matrix2x2& z) const;
Matrix2x2 operator-(const Matrix2x2& z) const;
void Print() const;
};
#endif /* SUBMISSION_MATRIX2X2_HPP_ */
here's the implementation code:
#include "header.hpp"
#include <iostream>
//Constructor setting everything at 0
Matrix2x2::Matrix2x2()
{
val00 = 0.0;
val01 = 0.0;
val10 = 0.0;
val11 = 0.0;
}
//Overriden copy constructor
Matrix2x2::Matrix2x2(const Matrix2x2& other)
{
val00 = other.val00;
val01 = other.val01;
val10 = other.val10;
val11 = other.val11;
}
//filling a,b,c,d constructor
Matrix2x2::Matrix2x2(double a, double b, double c, double d)
{
val00 = a;
val01 = b;
val10 = c;
val11 = d;
}
//printing the matrix
void Matrix2x2::Print() const
{
std::cout << "{" <<"\n";
std::cout << val00 << "," << val01 << "\n" endl;
std::cout << val10 << "," << val11 << "\n" endl;
std::cout << "}" << endl;
}
//determinant calculator
double Matrix2x2::CalcDeterminant() const
{
return (val00 * val11 - val01 * val10);
}
//inverse calculator
Matrix2x2 Matrix2x2::CalcInverse() const
{
double det = CalcDeterminant();
Matrix2x2 M(val11 / det, -val10 / det, -val01 / det, val00 / det);
return M;
}
main function: #include #include "Matrix2x2.hpp"
int main(int argc, char* argv[]){
Matrix2x2 M(2, 3, -1, 0);
std::cout <<"Det M=" << M.CalcDeterminant() <<"\n";
M.CalcInverse();
M.Print();
return 0;
}