The type 'std :: default_random_engine' cannot be resolved

I want to generate some random double numbers using default_random_engine and uniform_real_distribution in the random header.

I use Eclipse for C / C ++ and MinGW to create my project.

  • Eclipse Version: 4.2.1
  • Version for development of Eclipse CDT C / C ++: 8.1.1.201209170703
  • Eclipse CDT GCC Cross Compiler Support Version: 1.1.0.201209170703
  • MinGW version: 4.6.2 (verified using "gcc -v")

When I type std :: default_random_engine in the editor, Eclipse tells me that the "Type" std :: default_random_engine cannot be resolved.

I already set up my project to support C ++ 11 functions

Then I wrote a list of initialized vector and a range to check for C ++ 11 support, the code works fine.

vector<int> ivec = {1, 2, 3}; for (int i : ivec) cout << i << " "; cout << endl; 

What happened to "std :: default_random_engine", what should I do to fix this?

+7
source share
1 answer

UPDATE: I sent the original answer for a long time, and it is out of date. I checked twice today (March 15, 2014): in Eclipse Kepler (Build id 20130614-0229) is enough

  • add to Project> Properties> C / C ++ Build> Settings, and then on the Tool Settings tab CCC C ++ Compiler> -std=c++11 flag -std=c++11 ,

  • then in the menu "Window"> "Settings"> "C / C ++> Build" on the tab "Detection", the parameters of the built-in CDT GCC compiler are selected and add the -std=c++11 flag to the command to get the compiler specifications. On my machine, it looks after the change:

    ${COMMAND} -E -P -v -dD -std=c++11 "${INPUTS}"

  • clean and rebuild your project and your index (Project> C / C ++ Index> Rebuild), because Eclipse tends to cache error messages and display them even if they disappear after changing the setting.

It really works on my machine. If this is not the case, you can take a snapshot: C ++ 11 has full support for Eclipse , although I am not sure of the correctness of this approach and I do not need to do this on my machine. As of March 7, 2014, users said that they helped them, while the above approach did not.


Original post now deprecated:

This seems to be a false error from the IDE.

Click on project properties, then C / C ++ General> Code Analysis> Syntax and semantic errors and deselection type cannot be resolved.

I also had to disable a bunch of other syntax and semantic errors, such as invalid arguments, invalid overloading, Symbol not allowed, etc. in my own projects. These dummy errors come from Codan .

(You may need to add __GXX_EXPERIMENTAL_CXX0X__ to the define / preprocessor macros, but not sure about that.)

Strike>

+6
source

All Articles