I have constructed a program that does the following:
-has one function that adds together two 3x3 matricies and returns a matrix3x3_t pointer.
-main creates two matricies and initializes all their values to 10.
-main stores the result of adding the two matricies together in a matrix called resultMatrix;
-main then attempts to output each value in the resultMatrix
The line that I have put all the '*'s is what is causing my problem
I get the following compile time error:Code:#include <iostream> #include <conio.h> using namespace std; typedef struct { int mat[3][3]; } matrix3x3_t; //This prototype SHOULD be set up to return a matrix3x3_t pointer // but I am not sure if I set it up correctly matrix3x3_t * MatrixAdd(matrix3x3_t *matrixA, matrix3x3_t *matrixB, matrix3x3_t *resultMatrix) { for(int row = 0; row < 3; row++) { for(int col = 0; col < 3; col++){ resultMatrix->mat[row][col] = matrixA->mat[row][col] + matrixB->mat[row][col]; } } return resultMatrix; } int main(void) { matrix3x3_t Matrix1[3][3] = { 10, 10, 10,10, 10, 10,10, 10, 10 }; matrix3x3_t Matrix2[3][3] = { 10, 10, 10,10, 10, 10,10, 10, 10 }; matrix3x3_t resultMatrix[3][3]; resultMatrix[3][3] = *MatrixAdd(&Matrix1[3][3], &Matrix2[3][3], &resultMatrix[3][3]); int OutPut; //asign values to this for(int row = 0; row < 3; row++) { //while not finished going through the rows for(int col = 0; col < 3; col++) { //while not finished going through the columns OutPut = 0; //put to zero before doing anything with it, just to be safe I guess ************OutPut = resultMatrix[row][col];*********** if(col == 3) cout << OutPut << endl; else cout << OutPut; }//col loop }//row loop cout << "Please don't hit a key, I'm serious, ACK!" << endl; getch(); return 0; }
[error]
Compiling...
matricies.cpp
C:\matricies.cpp(41) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'matrix3x3_t' (or there is no acceptable conversion)
Error executing cl.exe.
matricies.exe - 1 error(s), 0 warning(s)
[/error]
I have probably done something simple wrong, but I don't know what! pLEASe hElP ME!¿¿â*
Also, I tried aligning the numbers to look like a matrix when I created matrix1 and matrix2, but they just spread a few lines apart and I can't get them to line up the way I want them to.



LinkBack URL
About LinkBacks


