开发者

How to make two arrays into a function in c++?

开发者 https://www.devze.com 2022-12-10 20:52 出处:网络
I have two string arrays \"Array1[size]\" and \"Array2[size]\". They both have the same size. I would l开发者_JS百科ike to write a function which contains this two arrays but I am having problems in t

I have two string arrays "Array1[size]" and "Array2[size]". They both have the same size. I would l开发者_JS百科ike to write a function which contains this two arrays but I am having problems in the way that I am declaring them.

I am declaring it like this: void Thefunction (string& Array1[], string& Array2[], int size);

And when I call it I am calling it like this: Thefunction (Array1, Array2, size);

What I am doing wrong?

Thank you.


You're declaring a function which takes arrays of string references. You almost certainly want to take arrays of strings.

Like this:

void TheFunction(string Array1[], string Array2[], int size);


void TheFunction(string* Array1,string* Array2,int size) { ... }

Arrays decay into pointers automatically.


You can do:

template <std::size_t size>
void TheFunction(string (&Array1)[size], string (&Array2)[size]);
0

精彩评论

暂无评论...
验证码 换一张
取 消