2016-04-28 51 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