繁体   English   中英

将多个 Arrays 合并为一个 2D Array

[英]Merge multiple Arrays to one 2D Array

我在这里有这个代码片段:


#define byte uint8_t

byte pins0[11] = {  0,  1,  2, 3,   4,  5,  6,  7, 63, 64, 65};
byte pins1[11] = {  8,  9, 10, 11, 12, 13, 14, 15, 60, 61, 62};
byte pins2[11] = { 16, 17, 18, 19, 20, 21, 22, 15, 60, 61, 62};
byte pins3[11] = { 23, 24, 25, 26, 27, 28, 29, 30, 60, 61, 62};
byte pins4[11] = { 31, 32, 33, 34, 35, 36, 37, 38, 60, 61, 62};
byte pins5[11] = { 39, 40, 41, 42, 43, 44, 45, 46, 60, 61, 62};

byte *segPins[6] = {&pins0,&pins1,&pins2,&pins3,&pins4,&pins5};

编译器显示错误:

src\main.cpp:15:63: error: cannot convert 'byte (*)[11] {aka unsigned char (*)[11]}' to 'byte* {aka unsigned char*}' in initialization
 byte *segPins[11] = {&pins0,&pins1,&pins2,&pins3,&pins4,&pins5};
                                                               ^
src\main.cpp:15:63: error: cannot convert 'byte (*)[11] {aka unsigned char (*)[11]}' to 'byte* {aka unsigned char*}' in initialization
src\main.cpp:15:63: error: cannot convert 'byte (*)[11] {aka unsigned char (*)[11]}' to 'byte* {aka unsigned char*}' in initialization
src\main.cpp:15:63: error: cannot convert 'byte (*)[11] {aka unsigned char (*)[11]}' to 'byte* {aka unsigned char*}' in initialization
src\main.cpp:15:63: error: cannot convert 'byte (*)[11] {aka unsigned char (*)[11]}' to 'byte* {aka unsigned char*}' in initialization
src\main.cpp:15:63: error: cannot convert 'byte (*)[11] {aka unsigned char (*)[11]}' to 'byte* {aka unsigned char*}' in initialization
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1

在我看来, segPins是一个byte指针数组。 所以它应该通过编译器但它看到了不同?

你需要的是

byte *segPins[6] = {pins0,pins1,pins2,pins3,pins4,pins5};

这是因为&pins0指的是数组pins0的地址。

编辑

有关更多信息,请参阅问题的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM