title: How to pass an array of vectors to a function
body: <p>I have defined an array of vectors, and want to pass this array to a function. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>void gridlist(std::vector&lt;int&gt; *grid, int rows, int cols){
      ..... }
  
  int rows=4;
  int cols=5;
  std::vector&lt;int&gt; grid[rows][cols];
  
  gridlist(grid,rows,cols);
  </code></pre>
  
  <p>The only method which has worked for me to pass arrays to a function was by pointer (*) ?.</p>
  
  <p>I've tried different method according to following descriptions: <a href="https://stackoverflow.com/questions/8767166/passing-a-2d-array-to-a-c-function">Passing a 2D array to a C++ function</a>, but I didn't manage to get it working. </p>
  
  <p>I always get the following error:</p>
  
  <pre><code>could not convert '(std::vector&lt;int&gt; (*)[cols])(&amp; grid)' from 'std::vector&lt;int&gt; (*)[cols]' to 'std::vector&lt;int&gt;'
         gridlist(grid,rows, cols);
  </code></pre>
  
  <p>I don't know what I am doing wrong. What is, in general, considered the best/safest method to do that task?</p>