matrix class

ok i have to make a matrix class for a math library and im now Very lost with what im ment to do or how to do it the code i have so far is:

#include <iostream>
#include <math.h>
#include "Vector2.h"

class Matrix
{
private:
float data[3][3];

public:
Matrix()
{
}

~Matrix()
{
}

float Matrix::GetData(int Col, int Row )
{
return data[ Col ][ Row ];
}

float Matrix::SetData(int Col, int Row )
{
return data[ Col ][ Row ];
}

void SetTranslation( const vector2 &Translation );

void GetTranslation( const vector2 &Translation );

void TransformPoint( vector2 &Point );
};

inline void Matrix::SetTranslation( const vector2 &Translation )
{
}

inline void Matrix::GetTranslation( const vector2 &Translation )
{
}

inline void Matrix::TransformPoint( vector2 &Point )
{
//Transform and translate the point
}


and i need to now create operator functions for


Matrix + Matrix


how would i do this or can someone point me in the right direction on how to do it
Last edited on
1
2
3
4
5
6
7
8
Matrix operator +(Matrix a, Matrix b){
//you will have to make it a friend of Matrix
//or a member function
//Matrix Matrix::operator+(Matrix b){...
    Marix c;
    c.data[0][0] = a.data[0][0] + b.data[0][0];//repeat this for every row and col
    return c;
}

I think it should work.
I would strong suggest passing by const reference to avoid unnecessary copies:

1
2
3
Matrix operator+( const Matrix& m1, const Matrix& m2 ) {
    // ...
}

Topic archived. No new replies allowed.