gpt4 book ai didi

c++ - 将多个数组合并为一个二维数组

转载 作者:行者123 更新时间:2023-11-30 03:13:28 25 4
gpt4 key购买 nike

我这里有这段代码:


#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指的是数组pin0的地址。

编辑

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

关于c++ - 将多个数组合并为一个二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58684288/

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