returning a 2d array

How do you return a 2d Array from a fuction
Array parameters pass to function by reference. If the function modifies the content of its array parameter, the array of the caller changes. Therefore, you "return" via parameter.

Option 2 is to create a class that holds an array, and then return class object.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const int SIZE = 3;

int** return_array()
{
	int** array = new int*[ SIZE ];
	for ( int i = 0; i < SIZE; ++i )
	{
		array[ i ] = new int[ SIZE ];
	}

	return ( array );
}

int main()
{
	int** array = return_array();

	for ( int i = 0; i < SIZE; ++i )
	{
		delete array[ i ];
	}
	delete array;

	return ( 0 );
}
Topic archived. No new replies allowed.