【发布时间】:2015-03-30 20:19:00
【问题描述】:
我想将一个数组声明为 Struct 的成员之一。失败,编译器抛出如下错误:
error C2536: ... : cannot specify explicit initializer for arrays
这是我在 .h 文件中的结构:
struct CommandRepo
{
std::string root_command[5] = { "create", "edit", "remove", "list", "setting" };
std::string Base = "^(create|edit|remove|settings|list)(?: *)(?:--([a-zA-Z]*))";
std::string EachWord = "(\\w+)";
};
似乎(如在 SO 中某处所读),VSC2013 并不完全符合 C++11,并且该错误与缺乏合规性有关。真的吗?我该如何解决?
【问题讨论】:
-
在 Visual Studio 齐心协力之前,您必须在构造函数中以老式的方式进行操作。或者,如果它永远不会改变,您可以将其设为静态常量。
-
你可以试试 Visual Studio 2015 Preview。
标签: c++ visual-studio c++11 visual-studio-2013