首页 > 解决方案 > 面向 C/C++ 开发人员的 Eclipse IDE:错误显示“无效参数”错误?

问题描述

我在 Eclipse IDE for C/C++ Developers Photon (4.8.0) 中收到无效参数错误map_name.insert(make_pair("string_name", int_name);

我正在使用 GCC 8.2.0。我正在用 STL 尝试一些简单的东西。

尝试两者insert(make_pair())insert(pair<string, int>())得到相同的 IDE 错误(语义错误)。这是为什么?

代码:

#include <iostream>
#include <map>
using namespace std;

int main()
{
    map<string, int> ages;

    ages["Mike"] = 21;
    ages["Johnny"] = 20;
    ages["Vicky"] = 30;
    ages["Mike"] = 42;

//  ages.insert(make_pair("Peter", 100));
    ages.insert(pair < string, int > ("Peter", 100));

    for(map<string, int>::iterator it = ages.begin(); it!=ages.end(); it++)
    {
        cout<< it->first<<": "<< it->second<<endl;

    }

     return (0);
}

这是 IDE 中显示的错误:

错误

标签: c++eclipse-cdt

解决方案


GCC 8 附带的标准库实现使用称为 的类型特征内在函数__is_constructible,Eclipse CDT 的解析器尚不支持。

当使用 CDT 解析 GCC 8 的标准库代码时,这可能会导致误报错误。

如果您使用 GCC 7 或更早版本,则此代码不会出现任何错误。

更新这个 Eclipse 错误跟踪添加对__is_constructibleCDT 解析器的支持。它最近已被修复,尽管该修复尚未出现在 CDT 版本中。


推荐阅读