7

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

I use Eclipse for C/C++ & MinGW to build my project.

  • Eclipse version: 4.2.1
  • Eclipse CDT C/C++ Development Tools version: 8.1.1.201209170703
  • Eclipse CDT GCC Cross Compiler Support version: 1.1.0.201209170703
  • MinGW version: 4.6.2(checked using "gcc -v")

When I type std::default_random_engine in the editor, Eclipse prompts me that "Type 'std::default_random_engine' could not be resolved".

I have already configured my project to support C++11 features

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

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

What's wrong with the "std::default_random_engine", what should I do to fix this?

zyy7259
  • 525
  • 1
  • 6
  • 15
  • 2
    It is possible that the libstdc++ that comes with your compiler does not support the newer standard library features, but that your compiler does support the newer language features. – X-Istence Oct 29 '12 at 05:46
  • try std::tr1::default_random_engine – Denis Ermolin Oct 29 '12 at 06:52
  • 1
    You _do_ include ``? Also, even if Eclipse doesn't recognize it, does it build properly anyway? – Some programmer dude Oct 29 '12 at 08:22
  • @JoachimPileborg Hah +10, See if it compiles before complaining about *Eclipse*'s non-working C++11 IDE. – Christian Rau Oct 29 '12 at 08:43
  • Sorry for replying your guys so late. I'm learning using this website and not familiar with it yet. Please look at the first answer below. I agree with it. And Eclipse builds properly even if it doesn't recognize it... – zyy7259 Jan 06 '13 at 11:53

1 Answers1

7

UPDATE: It's been a long time since I posted the original answer and it has become outdated. I double-checked today (Mar 15, 2014): in Eclipse Kepler (Build id 20130614-0229) it is sufficient to

  • add under Project > Properties > C/C++ Build > Settings then on the Tool Settings tab GCC C++ Compiler > Miscellaneous the -std=c++11 flag,

  • then under Window > Preferences > C/C++ > Build > Settings on the Discovery tab chose CDT GCC Built-in Compiler Settings and add the -std=c++11 flag to Command to get compiler specs. On my machine it looks like this after the change:

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

  • clean and rebuild both your project and your index (Project > C/C++ Index > Rebuild) as Eclipse tends to cache error messages and show them even though they are gone after changing the settings.

This works on my machine for sure. If it doesn't on yours, then you might want to give a shot to this: C++11 full support on Eclipse although I am neither sure about the correctness of this approach nor was it necessary to do it on my machine. As of March 7, 2014 users claim that it helped them whereas the above approach didn't.


The original post, now outdated:

It seems to be a false error from the IDE.

Click on the project properties, then C/C++ General > Code Analysis > Syntax and Semantic Errors and deselect Type cannot be resolved.

I also had to disable a bunch of other Syntax and Semantic Errors, such as Invalid arguments, Invalid overload, Symbol is not resolved, etc. in my own projects. These bogus errors come from Codan.

(You might have to add __GXX_EXPERIMENTAL_CXX0X__ to your defines / preprocessor macros, not sure about this one though.)

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • And did it help? Does the same code compile outside the Eclipse? – Ali Jan 06 '13 at 11:36
  • Thanks a lot! And sorry for replying your answer so late. At the very start I wondered that if there are some ways milder, but recently I meet some more such errors and so I do as you suggested. – zyy7259 Jan 06 '13 at 11:42
  • Sorry I'm learning using this website. And I want to edit my comment bu it said "Comments may only be edited for 5 minutes". I didn't see your reply and I delete my first comment. It do helps a lot. Now the errors disappear. I haven't try to compile the code outside the Eclipse – zyy7259 Jan 06 '13 at 11:45
  • BTW, Eclipse builds properly even if it doesn't recognize it – zyy7259 Jan 06 '13 at 11:55
  • @zyy7259 Most C++ IDE's have, at the present, rather lacking support for C++11. Haven't found one yet that I wasn't able to trip up somehow. – Cubic Jan 06 '13 at 11:56
  • @Cubic I choose Eclipse just because I like its UI :) – zyy7259 Jan 06 '13 at 12:06