gpt4 book ai didi

C++ 错误 : a brace-enclosed initializer is not allowed here before ‘{’ token

转载 作者:搜寻专家 更新时间:2023-10-31 02:21:01 26 4
gpt4 key购买 nike

简单问题:

我正在尝试在 C++ 类声明中初始化一个数组:

using namespace std;
#include <string>
class myClass{
public:
string myArray[] = {"a","b","c"};
};

我收到错误:

错误:在“{”标记之前不允许使用大括号括起来的初始值设定项

最佳答案

不,如果没有兼容的 C++11 编译器,您不能在其声明中初始化成员数组。您必须在构造函数中初始化数组成员。如果您知道初始化数组的元素数量,请不要使用开放数组。

关于C++ 错误 : a brace-enclosed initializer is not allowed here before ‘{’ token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31953419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com