Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: no matching function for call to 'make_pair(int&, Quest*)'

I get this weird error in g++; it compiles fine in Visual Studio.

struct Quest
{
    static map<int, Quest*> Cache;
};

Quest *Quest::LoadFromDb(BaseResult& result, int *id)
{
    Quest *ret;
    if(result.Error())
    {
        if(id)
            Cache.insert(make_pair<int, Quest*>(*id, NULL)); // <--- Problematic line

        return NULL;
    }

// ...
}

Exact error:

DataFilesStructure.cpp:9135:58: error: no matching function for call to 'make_pair(int&, Quest*)'

like image 638
Krevan Avatar asked Aug 24 '10 17:08

Krevan


3 Answers

You are most probably using the C++0x version of the libstdc++ library. C++0x declares make_pair as

template <class T1, class T2>
pair<V1, V2> make_pair(T1&& x, T2&& y) noexcept;

If T1 is int, then x is int&&, and therefor cannot take lvalues of type int. Quite obviously, make_pair is designed to be called without explicit template arguments

make_pair(*id, NULL)
like image 200
Johannes Schaub - litb Avatar answered Nov 15 '22 00:11

Johannes Schaub - litb


Simply remove the template parameters:

Cache.insert(make_pair(*id, NULL));

This should fix your problem.

like image 22
LBF Avatar answered Nov 15 '22 02:11

LBF


Does it work with an explicit cast?

if (id)
    Cache.insert(make_pair<int, Quest*>(int(*id), NULL));

Also, a cpp file with 9000 lines, really?

like image 13
fredoverflow Avatar answered Nov 15 '22 02:11

fredoverflow