title: Dynamic allocated class object
body: <p>I have simple class which you can see below:</p>
  <h2>Questions</h2>
  <ol>
  <li>Can I have in my <code>Playground</code> class constructor like this <code>Playground(int aRow, int aColumn);</code> If <em><strong>YES</strong></em> how I must allocate memory in then case for elements of row and column ? If <em><strong>NO</strong></em> why ?</li>
  <li>Why I can't write <code>mPlayground[0][0] = 0</code> and what can I do to do that ? If I can of course.</li>
  </ol>
  <h3>Playboard.h</h3>
  <pre><code>#pragma once
  #ifndef PLAYBOARD_H
  #define PLAYBOARD_H
  
  class Playground
  {
  public:
      Playground()
      {       
      }
  };
  
  class Playboard
  {
  public:
      Playboard();
      ~Playboard();
  
  private:
      Playground** mPlayground;
      int mRows;
      int mColumns;
  
  public:
      void Initialize(int aRow, int aColumn);
  };
  
  #endif /** PLAYBOARD_H */
  </code></pre>
  <h3>Playboard.cpp</h3>
  <pre><code>#include &quot;Playboard.h&quot;
  Playboard::Playboard()
  {
      mPlayground = 0;
  }
  
  void Playboard::Initialize(int aRow, int aColumn)
  {
      // Set rows and columns in order to use them  in future.
      mRows = aRow;
      mColumns = aColumn;
  
      // Memory allocated for elements of rows.
      mPlayground = new Playground*[aRow];
      // Memory allocated for elements of each column.
      for (int i=0; i&lt;aRow; i++)
          mPlayground[i] = new Playground[aColumn];
  }
  
  Playboard::~Playboard()
  {
      // Free the allocated memory
      for (int i=0; i&lt;mRows; i++)
          delete[] mPlayground[i];
      delete[] mPlayground;
  }
  </code></pre>