title: operator overloading [][] 2d array c++
body: <p>I have a 2D array and I want to define a function that returns the value of the index that the user gives me using operator overloading.
  In other words:</p>
  <pre><code>void MyMatrix::ReturnValue()
  {
      int row = 0, col = 0;
      cout &lt;&lt; &quot;Return Value From the last Matrix&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;----------------------------------&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Please Enter the index: [&quot; &lt;&lt; row &lt;&lt; &quot;][&quot; &lt;&lt; col &lt;&lt; &quot;] =&quot; &lt;&lt; ((*this).matrix)[row][col] &lt;&lt; endl;
  }
  </code></pre>
  <p>The operation <code>((*this).matrix)[row][col]</code> should return an <code>int</code>.
  I have no idea how to build the <code>operator [][]</code>.<br/>
  Alternatively, I could concatenate a couple of calls to the <code>operator []</code>, but I didn't succeed in it, because the first call to that operaror will return <code>int*</code> and the second one will return <code>int</code>, and it compel to build another operator, and I dont want to do that.</p>
  <p>The data matrix is defined like</p>
  <pre><code>int** matrix; matrix = new int*[row];
  if (matrix == NULL)
  {
      cout &lt;&lt; &quot;Allocation memory - Failed&quot;;
  }
  for (int i = 0; i &lt; row; i++)//Allocation memory
  {
      matrix[i] = new int[col];
      if (matrix[i] == NULL)
      {
          cout &lt;&lt; &quot;Allocation memory - Failed&quot;;
          return;
      }
  }
  </code></pre>
  <p>What can I do?
  Thank you,</p>