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]);
精彩评论