title: C++ cropping a contiguous 2D array
body: <p>Let's say that I have an array called image which is a long <strong>contiguous</strong> array of "size" elements - as defined bellow.
  I'd like to crop this array (then getting a sub matrix) then, by modifying the sub array I'll automatically modify the source image (reference).</p>
  
  <p>Be aware that the crop operation will return a <strong>non-contiguous array</strong>. This is in fact the problem.</p>
  
  <p>Is there a way to do this elegantly in C++?</p>
  
  <p>By the way, I'm <strong>not interested</strong> by using OpenCV, boost, etc...</p>
  
  <p>thanks for your help.</p>
  
  <pre><code>template &lt;class Type&gt; class Image
  {
  private:
      Type *image;
  
  public:
  
      int rows;
      int cols;
      int size;
  
      Image(int rows, int cols): rows(rows), cols(cols)
      {
          image = new Type[size = rows*cols];
      }
      ~Image()
      {
          delete [] image;
      }
      Type &amp; at(int i, int j)
      {
          return image[cols*i + j];
      }
      void print()
      {
          for(int i = 0; i &lt; rows; ++i)
          {
                  for(int j = 0; j &lt; cols; ++j)
                      cout &lt;&lt; at(i,j) &lt;&lt; " ";
                  cout &lt;&lt; endl;
          }
          cout &lt;&lt; endl;
  
      }
  
  }; 
  </code></pre>