2016-04-28 59 views
1

我必须声明这个公共方法的类:C++ 11均匀初始化不通过 “g ++ -std =的C++ 0x” 工作

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

它采用统一初始化(这里只是{}) ,来自C++ 11的一个特性。编写clang++ -std=c++11时,这不会产生任何问题。但是当我使用g++ -std=c++0x我得到这个:

error: expected primary-expression before '{' token 

不应该把我的C++ 11的支持-std=c++0x选项?

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

我使用G ++ 4.6在Ubuntu 12.04

+1

不确定你所要求的'std = C++ 0x'不是C++ 11的支持,它在4.6之前的gcc开发人员所理解的是11之前。如果你想要完整的C++ 11,使用'-std = C++ 11'。 – SergeyA

+0

看起来像一个海湾合作委员会的错误。它在4.7.3及以上版本中编译:https://godbolt.org/g/gy9Kb5 – NathanOliver

+0

现在有了C++ 11/C++ 14,没有必要使用C++ 0x/C++ 1y。一旦C++ 17出来,C++ 1z也不需要。 – Jarod42

回答

1

GCC 4.7 release notes

使用标准C++这样的声明方法时,编译器不给我任何错误

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.

来自C++11 in GCC project page

​​

不好的消息,您需要升级您的编译器才能使用C++ 11支持。

0

GCC 4.6不支持所有的C++ 11个的特点:

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

我建议你升级到最新版本的GCC,并与标志编译-std=c++11甚至-std=c++14

相关问题