I am trying to use a function to find the number of the row that a specific string is in. The function I am using is:
1 2 3 4 5 6 7 8
int seqSearch(birdList list[][NUM_COLUMNS], int listsize ,int which_col, string searchItem)
{
int loc;
for (loc = 0; loc < listsize; loc++)
if (list[loc][0] == searchItem)
return loc;
return -1;
}
When I run my program, it comes up with the error "error: no match for'operator==' in '(*(list + ((sizetype)(((unsigned int)loc) * 16u))))[0] == searchItem'| ". Can anyone help? I don't understand why this won't work. I have used this same function on other programs before.
It looks like list is an array of birdList and searchItem is a string. Did you overload the operator== in your birdList class so you can compare to a std::string?
You will have to define the operator== in your birdList class (Or whatever you called it). Right now like vlad said the compiler has no idea what it is supposed to be comparing.
If you can post your class header and also a description of what you want the '==' operator to do, we can give you suggestion on how to go about this if you don't know.
I did not. How do I go about doing that? I am a C++ noob.
Edit: I'm not sure about the classes. We have not been taught that yet (I've been told my professor sucks). Here are the prototypes, the struct for the array, and the includes:
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
struct birdList
{
string species;
int num_Birds;
};
constint ARRAY_SIZE = 200;
constint NUM_COLUMNS = 2;
void getData(ifstream& inFile, birdList list[][NUM_COLUMNS], int& listSize);
void printList(const birdList list[][NUM_COLUMNS], int listSize) ;
void printOne ( birdList one);
void num_Birds_change (birdList list[][NUM_COLUMNS], int listsize, int row);
int seqSearch(birdList list[][NUM_COLUMNS], int listsize ,int which_col, string searchItem);
Edit 2: Here is where it asks the user for the name of a bird:
1 2 3
cout << "Type the bird you would like to change the number spotted of (use '_' for spaces):" << endl;
cin >> birdName;
row = seqSearch( list , number , 0, birdName);
Could you please post your class and a description of how you want the == operator to behave? By that I mean do you want the == operator to compare a certain member in your class with a string? Or something else?
I want the == operator to basically say (but not literally, of course): I found birdName on row x. Then, I will have the program change the number of those birds spotted to a user input integer.
Edit: Also want to note I've never used the == operator for strings. It was just something I thought might work. Normally, I have used this function to compare the list to a integer.
I did that, which fixed the == operator issue, but now I am getting error: request for member 'species' in '*(list + ((sizetype)(((unsigned int)loc) * 16u)))', which is of non-class type 'birdList [2]'|
Edit: Thanks for noticing that, Zereo. That has been removed (I had copy and pasted from a previous program I had written and did not remove that). The error is still there, though.
Getting rid of the 2D array and making it a 1D array seems to have solved the problem!!! I've been doing a lot with multidimensional arrays lately and had that on the brain!! Thanks you all very much, and thank you especially, Vlad!