I need to create an operator that will copy the contents in one array to another. A.K.A an equal operator. I am thinking something along these lines:
operator=(string array[10][10], string array2[10][10])
{
int row = 0; int column = 0;
for(column=0; column<=9; column++)
{
for(row=0; row<=9; row++){
array2[row][column]=array[row][column];
}
}
}
I am just not sure on the syntax of operator declarations which is my problem. I know how to make the inside code even if I got the code displayed above wrong. I am just not sure how to write the “operator=(string ….)”
You can’t. For two reasons
What you can do is
Have a named function instead of operator
wrap the array into a class
use
vector<vector<string> >which already has the assignment (<– my vote goes here)1As to why these have to be members, you can see this question of mine: Rationale of enforcing some operators to be members