I'm not sure how this works with arrays (I never use them because they confuse me), but generally when you want "complicated" returns, you can pass-by-reference the object as a parameter to the function and then store it.
For example, when you want to return a vector (sort of array-like container type) of ints, it's easier to do this:
1 2 3
|
void returnVector(vector<int> &ints) {
(fill vector here)
}
|
To do the exact thing you want, you could for example do this:
1 2 3 4 5 6 7 8 9
|
void fillAndReturnVector(vector<vector<int>> &intArray) {
intArray.resize(2);
intArray[0].resize(2);
intArray[1].resize(2):
intArray[0][0] = 5;
intArray[0][1] = 10;
intArray[1][0] = 3;
intArray[1][1] = 6;
}
|
Then call it at such:
1 2
|
vector<vector<int>> testingArray;
fillAndReturnVector(testingArray);
|
That 2dimensional vector will now act just like an Array. I imagine you can do the same with actual arrays, but I don't touch the things in C++.
[edit]
Some additional explanation on the vector things: A vector has no pre-defined size. By using .resize(int), you can set the size.
The first resize call (on intArray itself) sets the first dimension of the "array"; the second and third calls set the second dimension of the "array" (a 2dimensional vector doesn't have to be a full "NxM matrix", so every row can have a different length if wanted).