我正在尝试做这样的事情:
struct SomeStruct {
const char *bytes;
const char *desc;
};
SomeStruct example = { { 0x10, 0x11, 0x12, 0x13 }, "10-13" };
为什么这不起作用?
最佳答案
可能是因为 { 0x10, 0x11, 0x12, 0x13 }
是一个 char
数组,而不是指向 char
的指针。
试试 SomeStruct example = { "\x10\x11\x12\x13", "10-13"};
代替。
关于c++ - 如何在结构内联中分配字符数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337755/