【发布时间】:2016-12-10 06:30:09
【问题描述】:
下面这段代码prints 0 compiled with vc++和prints 1 compiled with g++ or clang++:
#include <iostream>
#include <vector>
struct S
{
S() = default;
std::vector<int> v{0};
};
int main()
{
std::vector<S> s{{}};
std::cout << s.front().v.size() << std::endl;
}
这是 vc++ 中的错误吗?
如果提供了用户定义的构造函数(S() {}; 而不是S() = default;)vc++ starts to print 1, too。
【问题讨论】:
-
看起来确实像 vc++ 编译器中的编译器错误。
-
我似乎记得 C++17 中即将发生变化,即大括号初始化程序只有一个项目。如果将 0 更改为 13 会发生什么?
-
@Cheersandhth.-Alf 例如
std::vector<int> v{ 11,22 };产生同样的问题。
标签: c++ visual-c++ initialization c++14 list-initialization