title: Swap multi-dimensional arrays in C++
body: <p>(Note: I'm currently learning C++, so if there is a better way to do what I am doing, explanations would be helpful.)</p>
  
  <p>I am making Conway's Game of Life in C/C++ and have the following code:</p>
  
  <pre><code>bool ** previous;
  bool ** current;
  
  void init() {
      previous = new bool*[width];
      current = new bool*[width];
      for (int i =0; i &lt; width; i++) {
          previous[i] = new bool[height];
          current[i] = new bool[height];
      }
  }
  </code></pre>
  
  <p>The reason for the dynamic arrays is that the width and height are given by the user at runtime. If I had one-dimensional arrays, I could do the following:</p>
  
  <pre><code>bool * previous;
  bool * current;
  
  void () {
      bool * temp = current;
      current = previous;
      previous = temp;
  }
  </code></pre>
  
  <p>However, this approach does not work as hoped with the two-dimensional array. As it is technically an array of arrays, do I have to swap each sub-array pointer individually? Is there a better way to go about defining multi-dimensional arrays and swapping them?</p>
  
  <p>Edit: I have yet to really use any C++ specific features, so if I can do this in pure C, I'd prefer that.</p>