Hi,
I have just started learning classes and I have to make a matrix class. I know matrix math so that is not an issue, basically I have an h and cpp with function names and parameters and just have to define them. My problem is that Im stuck at the first one as I don't know how to use the parameters I am supposed to correctly. I'll post the h and what I am trying to do with the first function. The Exercises::Multiply is something that is setup already and I have no access to so I have know idea what is in it, basically it tests if what I have is correct or not. Im sure I am doing something completely stupid but I am a newb, I know the parameters arent arrays but I have no idea how else to use them in this function. Anyway if anyone can help me with this one i'll finally be able to work on the rest.

These are the errors I get:
error C2676: binary '[' : 'CMatrix' does not define this operator or a conversion to a type acceptable to the predefined operator

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)

could be 'CMatrix &CMatrix::operator =(const CMatrix &)'
1> while trying to match the argument list '(CMatrix, int)'

Sorry for the length and thanks in advance.

.h

#ifndef __MATRIX_H__
#define __MATRIX_H__

class CMatrix
{
public:
	float m_fMatrix[4][4];
};

#endif // __MATRIX_H__

.cpp

#include <cmath>
#include "matrix.h"

void 
Exercises::Multiply(const CMatrix& _rLHS, const CMatrix& _rRHS, CMatrix& _rResult)
{
    for (int i = 0; i < 4; i++) 
	{
		for (int j = 0; j < 4; j++) 
		{
			_rResult = 0;
            for (int k = 0; k < 4; k++) 
			{
				_rResult += m_fMatrix[i][k] * m_fMatrix[k][j];
			}
            m_fMatrix[i][j] = _rResult;
		}
	}	
}

Recommended Answers

All 2 Replies

You have some confusion between types in your Exercises::Multiply function. I think it should be something more like:

void 
Exercises::Multiply(const CMatrix& _rLHS, const CMatrix& _rRHS, CMatrix& _rResult)
{
   for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
         /* Need a temp variable to sum elements */
         float temp = 0;
         for (int k = 0; k < 4; k++) {
            /* Sum elements, use '.' operator on each CMatrix to get at their internal arrays */
            temp += _rRHS.m_fMatrix[i][k] * _rLHS.m_fMatrix[k][j];
         }
         /* Use the '.' operator to assign the element value to the correct element of _rResult */
         _rResult.m_fMatrix[i][j] = temp;
      }
   }	
}

There isn't enough information in your post to really know what is going on with the fact that the multiply function appears to be in another class or namespace called Exercises so you may get additional problems from that, or you might not. Hope that's some help

Thanks ravenous thats exactly what I needed, even if I didnt really know what I was trying to say. Thanks again!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.