C++:struct作为函数参数的数组

Owe*_*wen 1 c++ parameters struct function

我有一个结构:

typedef struct
{  
   int nNum; 
   string str;   
}KeyPair;
Run Code Online (Sandbox Code Playgroud)

假设我初始化我的结构:

KeyPair keys[] = 
{    {0, "tester"},  
     {2, "yadah"},  
     {0, "tester"} 
};  
Run Code Online (Sandbox Code Playgroud)

我想在函数中使用初始值.如何将此数组结构作为函数参数传递?

我有:

FetchKeys( KeyPair *pKeys)
{
     //get the contents of keys[] here...   
}
Run Code Online (Sandbox Code Playgroud)

Chu*_*dad 5

怎么样?

template<int N> void FetchKeys(KeyPair const (&r)[N]){}
Run Code Online (Sandbox Code Playgroud)

编辑2:

甚至

template<int N> void FetchKeys(KeyPair const (*p)[N])
Run Code Online (Sandbox Code Playgroud)

打电话给

FetchKeys(&keys);
Run Code Online (Sandbox Code Playgroud)