Erroneous “Unable to resolve identifier” in Netbeans

空扰寡人 提交于 2019-12-29 00:41:35

问题


My program compiles fine, but Netbeans tells me "Unable to resolve identifier 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.

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.

Minimal example:

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

EDIT: the same problem arises where using nullptr

EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.


回答1:


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. 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. You have to set BOTH or it will still give false errors!




回答2:


Autocomplete and sometimes even syntax highlighting are always faulty with 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. 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.




回答3:


I had the same situation. This was occurred because I used .c file instead of .cpp




回答4:


This will solve the problem:

  1. Right click on "Project".
  2. Select "Code Assistance".
  3. Clean C/C++ cache.
  4. Restart IDE.



回答5:


for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions: change:__cplusplus=199711L to:__cplusplus=201402L for C++14 or to __cplusplus=201103L for C++11




回答6:


I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.




回答7:


To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.



来源:https://stackoverflow.com/questions/30686264/erroneous-unable-to-resolve-identifier-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!