Pierre_colin
Pierre_colin

Reputation: 123

Curly brace uniform initilaization not recognised in Eclipse in c++

I am learning C++ and I am using Eclipse as an IDE. I downloaded the latest version for Mac (Version: 2018-12 (4.10.0)). I am trying uniform initialization but Eclipse gives me an error.

Here is the code:

#include <iostream>

int main()
{
   int x{ 5 }; 
   std::cout << x; 
   return 0;
}

If I type instead:

    int x(5); 

or

    int x=5;

It works! The error shown is the following:

Building file: ../src/HelloWorld2.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloWorld2.d" -MT"src/HelloWorld2.o" -o "src/HelloWorld2.o" "../src/HelloWorld2.cpp" ../src/HelloWorld2.cpp:5:10: error: expected ';' at end of declaration

Any ideas?

Upvotes: 0

Views: 476

Answers (1)

Pierre_colin
Pierre_colin

Reputation: 123

I couldn't find how to make Eclipse compatible for C++11, but then I found a website (took a while). Here is the solution.

  • On the project explorer window, right-click your project and choose properties at the bottom of the menu.
  • Go to "C/C++ Build" on the left, expand the options by clicking the small arrow and then select 'settings'
  • On the right side of the window, there is a list of settings. Select the 'Miscellaneous' one.
  • There will be a field called 'Other flags' to the right of that list. Add the following (put a space at the end of the current text).

    "-std=c++0x"

That's it!

Upvotes: 1

Related Questions