title: Initializing a 2D array of pointers as a member variable in C++
body: <p>I've been searching around Stack Overflow and the cplusplus forums with no luck. I am new to c++ and I'm currently working on a game for a school project. I have no problem creating, filling, destroying a 2d array of pointers and was using one in my game and it was working great. </p>
  
  <p>I created a new class for a player and moved the 2d array into that class. Now when I try to run my program I get a segmentation fault. Can anyone give me some insight into why this is happening? <em>bold I can't simply use a <code>std::vector&lt;&gt;</code> because the 2d array of pointers is a requirement.</em></p>
  
  <pre><code>class Player
  {
  public:
    Player();
    ...
    short** allocate_2d_array();
    ....
  protected:
    short **board;
    static const short BOARD_DIMENSIONS;
    ...
  };
  </code></pre>
  
  <p>The function</p>
  
  <pre><code>short** Player::allocate_2d_array()
  {
    short **array2d;
  
    // Insert columns
    for(int i = 0; i &lt; this-&gt;BOARD_DIMENSIONS; i++)
    {
      array2d[i] = new short[this-&gt;BOARD_DIMENSIONS];
      // Fill in the numbers
      for(int j = 0; j &lt; this-&gt;BOARD_DIMENSIONS; j++)
      {
        array2d[i][j] = 0;
      }
    }
  
    return array2d;
  }
  </code></pre>
  
  <p>Where it's called</p>
  
  <pre><code>Player::Player()
  {
    this-&gt;turns_taken = 0;
    // Prepare the board
    this-&gt;board = this-&gt;allocate_2d_array();
    ...
  }
  </code></pre>