大家好 我从 C 项目中获取了这段代码。我无法在 g++ 下以任何方式编译它。
我能用它做什么?
enum EnumIndexID{
ID_VALUE_A=2,
ID_VALUE_B=2
}
struct newtype {
enum MyEnumID eid;
const char *name;
} table[] = {
[ID_VALUE_A] = { MyEnumA, "ID_MSG_HeartbeatReq"},
[ID_VALUE_B] = { MyEnumB, "ID_MSG_HeartbeatReq"},
};
最佳答案
你确定你的编译器支持Designated Initializer吗?语法?
g++ 没有。 从该超链接:
Standard C89 requires the elements of an initializer to appear in a fixed order, the same as the order of the elements in the array or structure being initialized.
In ISO C99 you can give the elements in any order, specifying the array indices or structure field names they apply to, and GNU C allows this as an extension in C89 mode as well. This extension is not implemented in GNU C++.
关于c++ - 为什么这个 C 数组初始化不能在 g++ 下编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4829104/