gpt4 book ai didi

C++ : Array of struct as function parameter

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:10:15 25 4
gpt4 key购买 nike

我有一个结构:

typedef struct
{
int nNum;
string str;
}KeyPair;

假设我初始化了我的结构:

KeyPair keys[] = 
{ {0, "tester"},
{2, "yadah"},
{0, "tester"}
};

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

我有:

FetchKeys( KeyPair *pKeys)
{
//get the contents of keys[] here...
}

最佳答案

怎么样?

template<int N> void FetchKeys(KeyPair const (&r)[N]){}

编辑 2:

甚至

template<int N> void FetchKeys(KeyPair const (*p)[N])

调用为

FetchKeys(&keys);

关于C++ : Array of struct as function parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4284537/

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