title: Creating an unmodifiable 2d array in c++
body: <p>Quick background, I have some experience with java and currently new to c++.</p>
  
  <p>My question comes from an assignment in which we had to create 4 different magic squares, but for the nature of this particular question they can be any 2d array, so long as they are "exact" in values, only that they appear differently from each one. What I mean by that is if one 2d array looked like:</p>
  
  <p>1 2 3<br>
  4 5 6<br>
  7 8 9   </p>
  
  <p>the next one would be rotated 90 degrees </p>
  
  <p>7 4 1<br>
  8 5 2<br>
  9 6 3  </p>
  
  <p>and so on.. </p>
  
  <p>To make the first matrix I simply made a 2d array and created it using the magic square algorithm (irrelevant)</p>
  
  <pre><code>int** square = new int*[size]();
  for (int i = 0; i&lt;size; i++) {
     square[i] = new int[size]();
  }
  //set values to square .. irrelevant to show, could be anything
  
  //way down the code
  int** secondSquare = square;
  </code></pre>
  
  <p>For the second third and fourth ones all I would need to do is rotate the previous one to get the next rotated square. My problem however wasn't that I could not flip the arrays, but that while trying to flip them the values for the first square were also changing.</p>
  
  <p>Obviously this is more of a problem about being able to access the data in square and not change it while trying to add them to secondSquare.</p>
  
  <p>I tried making it so square was a modifiable pointer w constant unmodifiable values.</p>
  
  <pre><code>const int** square = new int*[size];
  </code></pre>
  
  <p>The problem with this is that I have to assign values after to square so this cannot be done. Also when I initialize secondSquare it gives me an error since it is of type int** and not const int**.</p>
  
  <p>Any better ways to handle problems with accessing data without changing values and setting both arrays (or objects really) properly on initialization?</p>