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*)'
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)
Simply remove the template parameters:
Cache.insert(make_pair(*id, NULL));
This should fix your problem.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With