请考虑以下代码段:
struct Foo {
};
template<typename T>
struct Bar {
const T foo;
};
int main() {
Bar<Foo> test;
}
Run Code Online (Sandbox Code Playgroud)
我用g ++ - 4.9.2用[-std = c ++ 11 -O0 -g3 -pedantic -Wall -Wextra -Wconversion]编译它并得到它error: uninitialized const member in ‘struct Bar<Foo>’.这很明显.
但是尝试添加std :: string作为Foo成员和程序编译!
#include <string>
struct Foo {
std::string test;
};
// (...)
Run Code Online (Sandbox Code Playgroud)
发生了什么?将测试类型替换为double会导致程序无法再次编译.什么字符串成员在课堂上变化?
从版本4.6开始,gcc似乎就像那样.
我正在尝试使用C++ 11初始化地图地图.我的编译器是VS 2013 Express.
unordered_map<EnumType, unordered_map<string, string>> substitutions = {
{
Record::BasementType,
{
{ "0", "" },
{ "1", "Slab or pier" },
{ "2", "Crawl" }
}
},
{
Record::BuildingStyle,
{
{ "0", "" },
{ "1", "Ranch" },
{ "2", "Raised ranch" }
}
},
// ... and so on
};
Run Code Online (Sandbox Code Playgroud)
它是编译但我在ntdll.dll中获得断点.但是这段代码的简化版本:
unordered_map<EnumType, unordered_map<string, string>> substitutions = {
{
Record::BasementType,
{
{ "0", "" },
{ "1", "Slab or pier" },
{ "2", "Crawl" }
}
},
// …Run Code Online (Sandbox Code Playgroud)