开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜