MAC上的叮当声不支持统一初始化
Does clang on Mac not support uniform initialization?
mac上的clang不支持统一的初始化?
我尝试编译以下代码,但编译器引起了错误。
#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<int> v = {3, 1, 9, 4};
std::cout << v[1] << std::endl;
}
错误:
vector.cpp:9:22: error: non-aggregate type 'std::vector<int>' cannot be initialized with an initializer list
std::vector<int> v = {3, 1, 9, 4};
^ ~~~~~~~~~~~~
1 error generated.
OS:MACOS 10.12.4
编译器版本:
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我怀疑您是不是将代码编译为C 11/14(-std=c++11
或-std=c++14
(?如果不;去做。clang 做支持您要做的事情。
相关文章:
- 内部结构初始化不起作用 - C++
- 初始化不是整数的巨大常量多维数组的最佳方法是什么?
- C++ 类型 'complex<double>' 中类中的复杂初始化不提供调用运算符
- 有没有办法初始化不涉及编写构造函数的新结构变量?
- 多变量初始化编译器支持
- 如何初始化不是静态的const成员
- 当INT初始化为浮动点值时,为什么填充初始化不会给出错误
- C++:unique_ptr初始化不正确
- 初始化不能从const char [3]转换为std :: string *
- 聚合初始化不支持构造函数访问
- 静态初始化不安全调用的线程安全
- 使用初始化列表的 POD 类型初始化不起作用
- C++:如何初始化不是整型的静态成员变量
- 初始化不正确的价值不良样式后,正在抛出异常
- C++11 数组初始化不会调用复制构造函数
- POD变量的直接初始化不起作用,但当将变量推到向量上时,复制初始化起作用
- 一堆变量正在取消初始化.不知道该怎么办
- 是否可以保证静态初始化不会覆盖显式初始化的值
- 静态初始化不使用_initterm而是使用 _Init_thread_header() / footer() 代替
- GCC 4.8.1 中的C++11:复制构造函数的列表初始化不起作用