使用c++/vC++将结构数组和2d数组传递给函数
Passing array of structures and 2d array to a function using c++/vC++
我需要帮助,因为我有一个Struct
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]);
这是正确的方式吗?否则请告诉我。
原型应该是
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);
我认为这将对您有所帮助:
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;
//declare My_Function
void My_Function(MyStruct[], unsigned char[][7]);
int main()
{
Info1 i;
Info2 j;
// use My_Function
My_Function(i.my_st,j.My_Array);
}
相关文章:
- 2D数组来自文本输入,中间有空格
- 如何使用用户输入在C++中正确填充2D数组
- 如何在C++中检查2D数组中负值的输入验证
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 如何将以逗号和空格分隔的整数读取到 2D 数组中?
- 如何在C++函数中声明静态 2D 数组?
- 如何声明一个可以在整个程序中使用的全局 2d 3d 4d .. 数组(堆版本)变量?
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 使用矢量将文本文件中的输入存储到 2D 数组中
- 获取 2D 数组 c++ 中的所有数字对
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 如何在构造函数中使用初始值设定项设置具有相同值的 2d 数组?
- 在 Python 和 c++ 2d 数组初始化之间.这是怎麽?为什么呢?
- 如何打印 2D 字符数组C++
- 如何将数组 2d 作为参数从函数传递并返回数组 2d 此函数
- 数组 2D 多个值
- 创建数组数组 (2D),而无需在 Java 中初始化内部数组
- 如何在C++中将文本文件传输到数组2D
- 从同一类的另一个方法调用数组2D-C++
- 获取地址在数组2d中的位置