Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to return a point to a 2d char array
    text
    copied!<p>I'm trying to return a pointer to a 2d char array (mainly just for practice using pointers since I don't understand them too well yet).</p> <p><strong>When I compile this I get the message:</strong></p> <pre><code>Maze Game.cpp(32): error C2440: 'initializing' : cannot convert from 'char (*)[8]' to 'char **' </code></pre> <p><strong>Line 32 is:</strong></p> <pre><code>char** acBoard = new char[8][8]; </code></pre> <p><strong>Here is the source code:</strong></p> <pre><code>#include "stdafx.h" #include &lt;iostream&gt; char** createGrid(); int main() { using namespace std; char** pBoard = createGrid(); char gameBoard[8][8]; for(int row = 0; row &lt; 8; row++) { int count = 0; for(int col = 0; col &lt; 8; col++) { char temp = **pBoard + count; gameBoard[row][col] = temp; cout &lt;&lt; gameBoard[row][col]; } cout &lt;&lt; endl; } delete pBoard; pBoard = 0; return 0; } char** createGrid() { char** acBoard = new char[8][8]; //Set wall positions acBoard[1][6] = 'X'; acBoard[1][7] = 'X'; acBoard[3][4] = 'X'; acBoard[3][6] = 'X'; acBoard[3][8] = 'X'; acBoard[4][1] = 'X'; acBoard[4][3] = 'X'; acBoard[4][4] = 'X'; acBoard[4][5] = 'X'; acBoard[4][6] = 'X'; acBoard[4][7] = 'X'; acBoard[5][1] = 'X'; acBoard[5][3] = 'X'; acBoard[5][4] = 'X'; acBoard[5][8] = 'X'; acBoard[6][1] = 'X'; acBoard[6][2] = 'X'; acBoard[6][3] = 'X'; acBoard[6][6] = 'X'; acBoard[6][8] = 'X'; acBoard[7][1] = 'X'; acBoard[7][5] = 'X'; acBoard[7][6] = 'X'; acBoard[7][8] = 'X'; acBoard[8][3] = 'X'; acBoard[8][5] = 'X'; acBoard[8][6] = 'X'; acBoard[8][7] = 'X'; acBoard[8][8] = 'X'; acBoard[1][8] = 'N'; acBoard[7][7] = 'T'; acBoard[5][2] = 'W'; acBoard[2][2] = '$'; return acBoard; } </code></pre> <p><strong>Can anyone explain to me why this is happening?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload