No match for 'operator=='?

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.
The compiler does not know how to compare an object of type birdList with an object of type std::string.
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?
closed account (3qX21hU5)
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

struct birdList
{
    string species;
    int num_Birds;
};

const int ARRAY_SIZE = 200;
const int 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);
Last edited on
closed account (3qX21hU5)
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?
How did you define your birdList class?
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.
Last edited on
I think taht instead of

if (list[loc][0] == searchItem)

in your original code snip shall be

if (list[loc].species == searchItem)

Also it seems that you defined the array incorrectly. I think that the arrray shall be a one-dimensional array of the structures.
Last edited on
closed account (3qX21hU5)
I agree with vlad that would be much simpler then overloading the == operator for your struct.

Try that instead.

Also noticed that you declare a parameter int which_col, but then you never use it.
Last edited on
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.
Last edited on
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!
Topic archived. No new replies allowed.