简体   繁体   English

Netbeans中错误的“无法解析标识符”

[英]Erroneous “Unable to resolve identifier” in Netbeans

My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string." 我的程序编译得很好,但Netbeans告诉我“无法解析标识符to_string”。

I tried everything in " Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful " and I set the "C++ standard" to "C++11" in the code assistance options. 我在“ Netbeans 7.2节目”中尝试了所有内容。 无法解析标识符“,虽然构建成功我在代码辅助选项中将“C ++标准”设置为“C ++ 11”。

This is the only function giving this problem so far. 到目前为止,这是解决此问题的唯一功能。 It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu. 然而它也是我使用的第一个C ++ 11特性,这使我相信它与Netbeans有关,而不是理解我正在使用C ++ 11,尽管我在代码辅助菜单中明确指定了它。

Minimal example: 最小的例子:

#include <string>
int main() {
    std::to_string(1);
}

EDIT: the same problem arises where using nullptr 编辑:使用nullptr会出现同样的问题

EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons. 编辑2:我突然意识到提到我不使用生成的Makefile,但是SCons可能很重要。

I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. 我知道这个问题已经有七个月了,但是自从它作为谷歌搜索的第二个结果出现后,我会告诉我想出的答案。 For Netbeans at least. 对于Netbeans至少。 Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. 转到项目属性并确保将“C Compiler” - >“C Standard”设置为C11,并将“C ++编译器” - >“C ++ Standard”设置为C ++ 11。 You have to set BOTH or it will still give false errors! 你必须设置BOTH或它仍然会给出错误的错误!

Autocomplete and sometimes even syntax highlighting are always faulty with C++. 使用C ++,自动完成,有时甚至语法突出显示总是有问题。 The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. 使用C ++和C ++ 11进行深入研究的越多,Eclipse和Netbeans就会开始用红色波浪线强调所有内容。 Some of my (correct and perfectly compiling) programs are a huge red wavy line. 我的一些(正确和完美编译)程序是一个巨大的红色波浪线。 I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it. 我建议您完全禁用错误标记并保持自动完成,但在许多情况下它只是不起作用,您必须充分利用它。

I had the same situation. 我有同样的情况。 This was occurred because I used .c file instead of .cpp 发生这种情况是因为我使用.c文件而不是.cpp

This will solve the problem: 这将解决问题:

  1. Right click on " Project ". 右键单击“ 项目 ”。
  2. Select " Code Assistance ". 选择“ 代码帮助 ”。
  3. Clean C/C++ cache. 清理C / C ++缓存。
  4. Restart IDE. 重新启动IDE。

对于Netbeans 8.2(在Linux上),只有以下工作对我__cplusplus=199711L :工具 - >选项 - >代码帮助 - >宏定义:更改: __cplusplus=199711L到: __cplusplus=201402L用于C ++ 14或到__cplusplus=201103L用于C + +11

我做了以上所有但是对我来说诀窍是认识到Makefile有g ++而不是g ++ -std = c ++ 11。

要在最新的netbeans 8.2或9版本中解决与c ++ 17相关的“无法解析标识符”,可能需要将宏定义__cplusplus = 201703L设置为默认的C ++ 14标准宏定义,无法解决出现的那些意外错误消息在编辑器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM