Hi, I am using a private helper function that takes one char parameter, and searches an array to see if any index matches the char key. However, I think I am doing something wrong in accessing my parameter? The error I get is "no operator "==" matches these operands." But I really don't know where or how to fix this. I have added some notes in my code that can hopefully make it easier to understand.
unsigned int ObjectCoordinater::find(char key) const
{
Object objects[OBJECT_COUNT]; //this array has been declared as a
//public in my .h file
int n = sizeof(objects) / sizeof(objects[OBJECT_COUNT]);
for (unsigned int i = 0; i < n; i++)
if (objects[i] == key) //this is where I am having issues!
return i;
return DOES_NOT_EXIST;
You are trying to compare an Object (whatever that is) with a char. How do you expect to do that? You might want to explain what you are actually trying to do, and also give the definition of Object.
Your expression for n is both unnecessary (you already know the size of the array) and refers to an element outside of array bounds.