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

标签 c++ c arrays visual-c++ character-arrays

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

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/

相关文章:

c - 执行 while 循环或 while 循环

arrays - JMeter:如何使用 jsonpath 计算数组中的 JSON 对象

java - Array 和 ArrayList 获取素数有什么区别?

c++ - 将模板化类型作为字符串获取

python - Boost.Python 向现有 PyObject 添加绑定(bind)(用于异常处理)

c - dlopen 无法为作为原型(prototype)的函数定义符号

c - RasDial 返回 633(正在使用的端口),但它不是

C 编程 - 灵活数组成员的非静态初始化

c++ - 类成员和依赖注入(inject)的对象与引用

c++ - 只有静态方法的类比命名空间更可取吗?