i have the following array as private member in 1 class:
bool array[100][100];
i need to use the filled up array in another class so i need a get method to return the array. but
bool[][] getArray();
and bool* getArray();
both does not work..
thanks!
How to return a multidimensinal array in C++?
try to use : return array[0][0];
Reply:You may use one of the following methods:
1. Return a bool** like -
bool** getArray() {
return array;
}
2. Take in a reference -
void getArray(bool **%26amp;arr) {
arr = array;
}
However, you would also need to know the 1st (row) and 2nd(column) size of the 2d array. Hence the following would be a better solution -
--
void getArray(bool **%26amp;arr, int %26amp;row, int %26amp;col) {
arr = array;
row = n_rows;
col = n_cols;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment