简体   繁体   中英

c++11 uniform initialization doesn't work with "g++ -std=c++0x"

I have a class that declares this public method:

virtual std::vector<float> operator()(const std::vector<float>& = {});

which uses uniform initialization (here just {} ), a feature from c++11. This doesn't give me any problem when compiling with clang++ -std=c++11 . But when I use g++ -std=c++0x I get this:

error: expected primary-expression before '{' token

Isn't the -std=c++0x option supposed bring me c++11 support?

The compiler doesn't give me any error when declaring the method using standard c++ like this:

virtual std::vector<float> operator()(const std::vector<float>& = std::vector<float>());

I am using g++ 4.6 on Ubuntu 12.04

From the GCC 4.7 release notes :

G++ now accepts the -std=c++11 , -std=gnu++11 , and -Wc++11-compat options, which are equivalent to -std=c++0x , -std=gnu++0x , and -Wc++0x-compat , respectively.

From the C++11 in GCC project page :

GCC 4.8.1 was the first feature-complete implementation of the 2011 C++ standard, previously known as C++0x.


Bad news, you need to upgrade your compiler to get working C++11 support.

GCC 4.6 doesn't support all of the c++11 features:

GCC provides experimental support for the upcoming ISO C++ standard, C++0x. This support can be enabled with the -std=c++0x.

I suggest that you upgrade to the latest GCC version, and compile with the flag -std=c++11 or even -std=c++14

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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