c++11 统一初始化不适用于 "g++ -std=c++0x"

标签 c++ c++11 g++ clang++ uniform-initialization

我有一个声明这个公共(public)方法的类:

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

-std=c++0x 选项不是应该给我带来 c++11 支持吗?

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

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

我在 Ubuntu 12.04 上使用 g++ 4.6

最佳答案

来自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.

来自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.


坏消息,您需要升级您的编译器才能获得有效的 C++11 支持。

关于c++11 统一初始化不适用于 "g++ -std=c++0x",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36920707/

相关文章:

c++ - 生产者和消费者——多线程

c++ - 表达式模板与手写代码

c++ - 在 SciTE 中链接 C++

c++ - 如何在 g++ 中设置警告以警告返回指向局部变量的指针?

c++ - Windows 上的链接 boost 问题

c++ - std::reference_wrapper<std::any> 上的类型特征

C++数组问题

c++ - 无法使用 boost::spirit::qi 解析 SQL 类型 where 条件

c++ - 将 lambda 表达式传递给模板函数时出现编译错误

visual-studio - 在 for_each 中端到端