最后他们做到了。MSVC12编译器现在允许统一初始化。但我发现,它的工作方式不同于带有-std=C++11标志的GNU GCC 4.8.1。
请考虑以下代码:
#include <vector>
#include <string>
#include <iostream>
struct Data
{
Data(const std::string& name, int x):
m_Name(name),
m_X(x)
{}
std::string m_Name;
int m_X;
};
std::vector<Data> datas =
{
Data("one", 1),
Data("two", 2),
Data("three", 3),
};
int main()
{
for(auto it = datas.begin(); it != datas.end(); ++it)
std::cout << it->m_Name << " " << it->m_X << "\n";
}与GCC的结果(如预期一样):
one 1
two 2
three 3(理想环节)
MSVC12的结果:
1
2
3就像字符串还没有初始化一样。
问题:
发布于 2013-09-23 14:43:54
这可能是VS2013预览中的一个bug。当前VS2013 RC生成的二进制文件的输出与g++一致。
https://stackoverflow.com/questions/17547913
复制相似问题