The following code is giving this error:
error: no match for 'operator[]' (operand types are 'S' and 'int')|"
in the lines 38, 40, 52, 53, 54, 54, 67, 67 (Yes, same error at at 54 and 67 two times).
#include <iostream>
using namespace std;
const int m=3;
class S
{
public:
int col;
char ch;
int getcolumn()
{
return col;
}
int getrow()
{
int t=ch; t-=65;
return t;
}
};
void input(S *mat)
{
int i,j;
for(i=0;i<m;i++)
{
cout<<endl<<"ROW "<<i+1;
for(j=0;j<m;j++)
{
cout<<endl<<"COLUMN "<<j+1<<endl;
cout<<"enter the number";
cin>>mat[i][j].col;
cout<<"enter the letter";
cin>>mat[i][j].ch;
}
}
}
void logic(S *orig,S *repl)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
int coll=orig[i][j].getcolumn();
int row=orig[i][j].getrow();
repl[row][coll]=orig[i][j];
}
}
}
void output(S *repl)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
cout<<repl[i][j].col<<repl[i][j].ch<<" ";
}
cout<<endl;
}
}
int main()
{
int i,j;
S orig[10][10],repl[10][10];
input(&orig[0][0]);
logic(&orig[0][0],&repl[0][0]);
output(&repl[0][0]);
return 0;
}
How can the error be solved? I am using code::blocks 17.12 with GCC compiler. I am quite new to c++ so please explain in a little bit more detailed manner.