问题描述:

I am getting this error when trying to do comparisons with a string array and a char using "==" and "!=". Does this mean I need to do some operator overloading? If so, can anyone point me in the right direction on how to do that(or another method) because i'm not too familiar with operator overloading yet.

bool legalMove(string list[][7], int row_start,

int column_start, int row_end,int column_end)

{

if(list[row_start][column_start] == 'S' && list[row_end][column_end] != ' ')

{

if((row_end == row_start + 1 && column_start == column_end) ||

(row_start == row_end && (column_end == column_start + 1

|| column_end == column_start - 1)))

{

return true;

}

else

{

return false;

}

}

else

{

return false;

}

}

网友答案:

You are comparing a std::string to a char by using ''. Try instead

if(list[row_start][column_start] == "S" && list[row_end][column_end] != " "){ }

If you are using std::string, that is a standard-type and you won't be able to overload the operator==. See here for a reference on std::string.

相关阅读:
Top