title: pass 2d array to a function in c++
body: <p>I am trying to pass a 2d array to a function in c++. The problem is that its dimension is not universal constant. I take the dimension as an input from the user and then try to pass the array. Here is what i am doind:</p>
  
  <pre><code>/*
   * boy.cpp
   *
   *  Created on: 05-Oct-2014
   *      Author: pranjal
   */
  #include&lt;iostream&gt;
  #include&lt;cstdlib&gt;
  using namespace std;
  
  
  class Queue{
  private:
      int array[1000];
      int front=0,rear=0;
  public:
      void enqueue(int data){
          if(front!=(rear+1)%1000){
              array[rear++]=data;
          }
      }
      int dequeue(){
          return array[front++];
      }
      bool isEmpty(){
          if(front==rear)
              return true;
          else
              return false;
      }
  };
  
  class Graph{
  public:
      void input(int matrix[][],int num_h){ //this is where I am passing the matrix
          int distance;
          char ans;
  
          for(int i=0;i&lt;num_h;i++){
              for(int j=0;j&lt;num_h;j++)
                  matrix[i][j]=0;
          }
          for(int i=0;i&lt;num_h;i++){
              for(int j=i+1;j&lt;num_h;j++){
                  cout&lt;&lt;"Is there route between houses "&lt;&lt;i&lt;&lt;" and "&lt;&lt;j&lt;&lt;": ";
                  cin&gt;&gt;ans;
                  if(ans=='y'){
                      cout&lt;&lt;"Enter the distance: ";
                      cin&gt;&gt;distance;
                      matrix[i][j]=matrix[j][i]=distance;
                  }
              }
          }
          cout&lt;&lt;"The matrix is: \n";
          for(int i=0;i&lt;num_h;i++){
              cout&lt;&lt;"\n";
              for(int j=0;j&lt;num_h;j++)
                  cout&lt;&lt;matrix[i][j]&lt;&lt;"\t";
          }
      }
  };
  
  int main(){
      Graph g;
      int num_h;
      cout&lt;&lt;"Enter the number of houses: ";
      cin&gt;&gt;num_h;
      int matrix[num_h][num_h];
      g.input(matrix,num_h); //this is where I get an error saying
                             // Invalid arguments ' Candidates are: void input(int (*)[], 
                             // int) '
      return 0;
  }
  </code></pre>
  
  <p>Help much appreciated. Thank you.</p>