Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将std::数组变量作为参数传递_C++_C_Std - Fatal编程技术网

C++ 将std::数组变量作为参数传递

C++ 将std::数组变量作为参数传递,c++,c,std,C++,C,Std,我需要帮助解决我面临的问题 我想要一个函数原型,它在两个实例上接受两种不同类型的参数 例如,如下所示: 我的结构如下所示: typedef struct BufferStruct { unsigned long BufferType; unsigned long TheAddress; } Buffer; 我有一个名为Test的函数,这个函数应该接受两种不同类型的参数 1)

我需要帮助解决我面临的问题

我想要一个函数原型,它在两个实例上接受两种不同类型的参数

例如,如下所示: 我的结构如下所示:

         typedef struct BufferStruct
         {
            unsigned long    BufferType;
            unsigned long    TheAddress;
          } Buffer;
我有一个名为Test的函数,这个函数应该接受两种不同类型的参数

  1) std::array<Buffer, 2> axBuffer; 
  2) Buffer axBuffer;

   void Test(??)/* function argument ?*/

 These are C functions and not C++.

 Can someone please help me in getting the appropriate function prototype for the function named "Test"?

 Advanced thanks.
1)std::array axBuffer;
2) 缓冲区axBuffer;
无效测试(??/*函数参数*/
这些是C函数,而不是C++。
有人能帮我为名为“Test”的函数获取合适的函数原型吗?
非常感谢。

C没有函数重载。使用单个函数实现此目的的最简单方法是获取指向-
缓冲区的指针和长度:

void Test(Buffer *buffer, size_t length);
使用单个
缓冲区调用此函数时

Buffer buf = ...;
Test(&buf, 1);
使用
std::array调用它时

std::array<Buffer, 2> buffers = ...;
Test(buffers.data(), buffers.size());

C中没有函数重载,这是不可能的。
void TestOne(Buffer *);
void TestMany(Buffer *, size_t);