Kre*_*van 7 c++ gcc compiler-errors
我在g ++中得到了这个奇怪的错误; 它在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;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
确切的错误:
DataFilesStructure.cpp:9135:58:错误:没有匹配函数来调用'make_pair(int&,Quest*)'
Joh*_*itb 19
您最有可能使用libstdc ++库的C++ 0x版本.C++ 0x声明make_pair为
template <class T1, class T2>
pair<V1, V2> make_pair(T1&& x, T2&& y) noexcept;
Run Code Online (Sandbox Code Playgroud)
如果T1是int,则x是int&&,因此不能采用类型的左值int.很明显,make_pair设计为在没有显式模板参数的情况下调用
make_pair(*id, NULL)
Run Code Online (Sandbox Code Playgroud)
fre*_*low 10
它是否适用于明确的演员?
if (id)
Cache.insert(make_pair<int, Quest*>(int(*id), NULL));
Run Code Online (Sandbox Code Playgroud)
还有一个9000行的cpp文件,真的吗?
小智 5
只需删除模板参数:
Cache.insert(make_pair(*id, NULL));
Run Code Online (Sandbox Code Playgroud)
这应该可以解决您的问题。
| 归档时间: |
|
| 查看次数: |
21581 次 |
| 最近记录: |