How to pass 2D array as read only to function by double pointer?
<p>I need to pass double pointer, which points to the first element of 2D array, to function in way that prevents the function from modifying any element from 2D array. I thought I can do it with const reference - <code>int** const &amp;board</code>, but it doesn't work like I expected. Moreover the 2D array cannot be declared as const, because it should be modifiable outside that function. How is such functionality possible? Here is working, simplified code in which I use it:</p>

<pre><code>#include &lt;iostream&gt;

class player
{
public:
    player(){}
                                 // returns player move
    int move(int** const &amp;board)
    {
        board[1][1] = 9; // should be illegal
        return 9;
    }
};

class game
{
    int** board;    
    player *white, *black;

public:
    game(player* player1, player* player2): white(player1), black(player2)
    {
        int i, j;

        board = new int* [8];

        for(i = 0; i &lt; 8; i++)
        {
            board[i] = new int [8];
            for(j = 0; j &lt; 8; j++)
                board[i][j] = 0;
        }
    }
                // gets moves from players and executes them
    void play() 
    {
        int move = white-&gt;move(board);

        board[2][2] = move; // should be legal
    }
                 // prints board to stdout
    void print() 
    {
        int i, j;

        for(i = 0; i &lt; 8; i++)
        {
            for(j = 0; j &lt; 8; j++)
                std::cout &lt;&lt; board[i][j] &lt;&lt; " ";
            std::cout &lt;&lt; std::endl;
        }
    }

};

int main()
{
    game g(new player(), new player());

    g.play();
    g.print();
}
</code></pre>
