所以我有一个结构如下:
typedef struct {
......
char* filenames[];
}
int myFunction(char* filenames[]) {
myStruct->filenames = filenames;
}
这给了我一个“灵活数组成员的无效使用”错误。为什么是这样?我知道我无法 malloc 我的结构数组,因此我不确定如果无法为其赋值,我将如何使用它。
最佳答案
您需要使用char** filenames
。 c++
不接受可变长度数组。
参见example .
作为建议,而不是答案,请使用 std::string
。或者如果您需要容器,std::vector<std::string>
。
关于c++ - 为结构体灵活数组赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29638944/