MakaraPr
MakaraPr

Reputation: 171

Error: No Match Function to Call

I want to make my vector, vector_list, not to have any duplicate data. Here the code:

int is_Tally(int num ) 
{
    vector<int> vector_list;
    for(int i=1; i< 1000;i++)
    {
        int item = (i*num)%10000;
        if (vector_list.empty())
        {
            vector_list.push_back(item);
        }
        else
        {
            if (find(vector_list.begin(), vector_list.end(), item)!=vector_list.end())
            {
                vector_list.push_back(item);
                if (vector_list.size()>15)
                {
                    return 0;
                }
            }
        } 
    }
    return vector_list.size();

And I got an error when I execute the code.

error: no matching function for call to 'find(__gnu_cxx::__normal_iterator<int*,     std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, int&)

Any suggestions? Thank.

Upvotes: 1

Views: 2868

Answers (3)

batman
batman

Reputation: 269

Try including algorithm header. I think then It should Work.

Upvotes: 1

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385098

The standard library function find is in the namespace std.

Write std::find.

Also don't forget to #include <algorithm>.

Upvotes: 6

Josh Engelsma
Josh Engelsma

Reputation: 2646

if (find(vector_list.begin(), vector_list.end(), item)!=vector_list.end())

It is complaining about this line of code. Apparently your find() function (not provided here) is not matching the way you have called it.

Make sure the find function has two parameters for a vector iterator followed by a parameter for an int, because this is what you are passing in your function call.

Also Note: Make sure the find function returns a vector iterator because that is what you are comparing it with using !=

Upvotes: 1

Related Questions