**NEW CODE SINCE LAST ANSWER**(changed all multidimensional array to single)
ANY other suggestions or help is appreciated!
Hai,
I got this error going in my .ccp.(no match for 'operator[]' in 'temp[0]') I have been trying to figure this out for awhile but can't. I know my code isnt finished but without finding what is wrong with this right now i can't see what else i have to do.
My objective:
-add, subtract and multiply matrices
-overload operators
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "matrix.h"
usingnamespace std;
int main(){
//Variables/Instances
int choice = 0;
int answer[9];
int arraysize = 0;//Used to keep track of how big the array that were put the file into is
int numberOfIntegers = 0;//number of total integers we pulled from file
int globalcounter= 0;//to keep track of where we are at in the array
int m1[9];
int m2[9];
string test = 0;//Just a test string (does not do anything)
int size = 0;//
matrix testm1;
matrix testm2;
matrix testanswer;
//open file to find length
ifstream myfile;
myfile.open ("input.txt");
//find size of array
while (!myfile.eof()){
getline(myfile, test);
arraysize++;
};
//close file to restart
myfile.close();
//declare array to hold strings coming from file
string strfile[arraysize];
//declare array to hold ints converted from file array
int file[arraysize];
//Open file
myfile.open("input.txt");
//Pull from strings file
while (!myfile.eof()){
size++;
getline(myfile, strfile[size]);
numberOfIntegers++;
};
//convert string array to int array
for(int t = 0; t < size; t++){
stringstream ssr(strfile[t]);
ssr >> file[t];
};
while (globalcounter != numberOfIntegers){
//Pulls the decision
choice = file[globalcounter];
globalcounter++;
//Seperate 9 integers from array to send to be turned into matrix 1
for(int i = 0; i < 8; i++){
m1[i] = file[globalcounter];
globalcounter++;
};
};
//Seperate 9 integers from array to send to be turned into matrix 2
for(int i = 0; i < 8; i++){
m2[i] = file[globalcounter];
globalcounter++;
};
};
//Set Variables to Matrix
for(int i = 0; i < 8; i++){
testm1[i] = m1[i];
};
for(int i = 0; i < 8; i++){
testm2[i] = m2[i];
};
//Decide what do do with
switch(choice){
case 1: //addition
//fill Matrix
testanswer=testm1+testm2;
break;
case 2: //subtraction
//fill Matrix
testanswer=testm1-testm2;
break;
case 3: //multiplication
//fill Matrix
testanswer=testm1*testm2;
break;
case 4:
myfile.close();
break;
};
};
system("PAUSE");
return EXIT_SUCCESS;
};
At this line specified above, you compiler looks for a definition of operator [] within the matrix class. Not finding one results in your error. Having an internal array representing a matrix doesn't mean that the semantics of that array will be automatically be translated to the class its declared in.
NB: In writing your overloaded definition of operator [], you might want to rethink how you're representing your matrix internally since it's multidimensional
I'm not sure how I would fix that. I don't want to have to overload the [] operator. Is there another variation of that statement that is syntacticly correct?
I don't even see an internal array in there anywhere...
Anyway, assuming you do end up with an internal array, the only way to really avoid overloading the array subscript operator is to expose the internal array. And in any case, overloaded the array subscript operator wouldn't let you have two of them in a row unless you created an intermediate type like "matrixRow" or something.