gpt4 book ai didi

c++ - 使用 c++/vC++ 将结构数组和二维数组传递给函数

转载 作者:行者123 更新时间:2023-11-30 18:55:58 25 4
gpt4 key购买 nike

我需要帮助,我有一个结构

typedef struct {  
unsigned char data0;
unsigned char data1;
// like this 8 bytes of data in my structure
} MyStruct;

typedef struct {
Mystruct my_st[8];
} Info1;

typedef struct {
unsigned char My_Array[8][7];
} Info2;

//now i want to pass the array of 8 structures in Info1 and 2D array of Info2 .
My_Function( &Info1->my_st[8], &Info2->My_Array[8][7]);

这是正确的方法,否则请告诉我。

最佳答案

原型(prototype)应该是

void My_Function(MyStruct (&my_st)[8], unsigned char (&My_Array)[8][7]);

这样调用它:

Info1 info1;
Info2 info2;
My_Function(info1.my_st, info2.My_Array);

但是这样会更简单:

void My_Function(Info1 &info1, Info2 &info2);

Info1 info1;
Info2 info2;
My_Function(info1, info2);

关于c++ - 使用 c++/vC++ 将结构数组和二维数组传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25865093/

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