我想将数组声明为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,并且该错误与缺乏合规性有关。真的吗?我该如何解决?
答案 0 :(得分:0)
是否可以使用std::vector
?如:
struct CommandRepo
{
std::vector<std::string> root_command = { "create", "edit", "remove", "list", "setting" };
std::string Base = "^(create|edit|remove|settings|list)(?: *)(?:--([a-zA-Z]*))";
std::string EachWord = "(\\w+)";
};
此结构的接口肯定会更改,但这可以让您初始化std::string
的列表。