How do you return a 2d array in C++?
<p>How do I return a 2d array in C++?</p>

<p>For example, I have the following method in java:</p>

<pre><code>public static int[][] getFreeCellList(int[][] grid) {
    // Determine the number of free cells
    int numberOfFreeCells = 0;
    for (int i=0; i&lt;9; i++) 
      for (int j=0; j&lt;9; j++)
        if (grid[i][j] == 0)
          numberOfFreeCells++;

    // Store free cell positions into freeCellList
    int[][] freeCellList = new int[numberOfFreeCells][2];
    int count = 0;
    for (int i=0; i&lt;9; i++)
      for (int j=0; j&lt;9; j++)
        if (grid[i][j] == 0) {
          freeCellList[count][0] = i;
          freeCellList[count++][1] = j;
        }
    return freeCellList;
  }
</code></pre>

<p>I'm trying to replicate this in C++.  Normally, I would pass in the 2d array i wanted to return as reference parameter of the method in C++.</p>

<p>However, as you see in the method above the size of the array being returned isn't known until run-time.</p>

<p>So, in this case I'm guessing I need to actually return a 2d array, right?</p>
