title: C++ 2D Array Alocation/Parameter Error
body: <p>I am attempting to create a function that takes 3 parameters (one the transmits the array between this function and main, an integer for length of first index of array, and an integer for length of 2nd index of array). Then in main, the user can set the length of an array himself.</p>
  
  <pre><code>void function (int** x, int length1, int length2)
  {     
      int** x = new int*[length1];    //error redefinition of formal parameter x
      for (int i = 0; i &lt; length1; ++i){
      x[i] = new int[length2];
  }   
      // given loop to be used after 2d array is allocated
      for (int i =0; i &lt;length1;i++)
         for(int j =0; j&lt;length2; j++)
         x[length1][length2] = i*j;
  }
  
  int main()
  {   
  int **y, s1, s2;
  
  cout &lt;&lt; "Enter the rows and columns: ";
  cin &gt;&gt; s1 &gt;&gt; s2;
  cout &lt;&lt; endl;
  
  function(y, s1, s2);
  for(int i =0; i&lt;s1; i++)
      for(int j=0; j&lt;s2;j++)
          cout&lt;&lt;"i = " &lt;&lt; i &lt;&lt; " j = " &lt;&lt; j &lt;&lt; "y[i][j] = " &lt;&lt;y[i][j] &lt;&lt; endl;
  
  delete []y;
  }
  </code></pre>
  
  <p>I get the error about a redefinition of formal parameter x. Everything I have read seems to say that I have allocated the 2D array correctly so is it the parameters that are passed incorrectly? I have tried moving around a few things but it hasnt helped; any help or direction is appreciated. thanks</p>
  
  <p>edit: If I change the parameter to (int**, int length1, int length2) it fixes the problem I described above, but now tells me y in the main function is unidentified. Do I need allocate the new array in main? I thought if I called the foo function, that would take care of it.</p>