title: Passing unknown Array to Function by reference (C++)
body: <p>I have spent a good hour trying to figure this out - how do I write this function (at top of code - insertionSort) that allows me to pass an array by reference to it. In a way that allows me to call '.size' on the array. It has to be an array for this assignment.</p>
  
  <p>I have tried not passing it by reference, dereferencing the array before calling size on it, etc.  I keep getting errors :(.</p>
  
  <p>This is the most recent compiler error for this code:</p>
  
  <p>insertionSort.cpp:11: error: <strong>parameter ‘A’ includes reference to array of unknown bound ‘int []’</strong>
  insertionSort.cpp: In function ‘void insertionSort(int (&amp;)[])’:
  insertionSort.cpp:13: error: <strong>request for member ‘size’ in ‘<em>(int</em>)A’, which is of non-class type ‘int’</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  //#include &lt;array&gt; - says no such file or directory
  
  using namespace std;
  
  
  void insertionSort(int (&amp;A)[])                 &lt;-----ERROR HERE
  {
      for (int j=1; j &lt;= A-&gt;size(); j++)         &lt;-----ERROR HERE
      {
          int key = A[j];
          //now insert A[j] into the sorted sequence a[0...j-1].
          int i = j-1;
          while (i &gt;= 0 &amp;&amp; A[i] &gt; key)
          {
              A[i+1] = A[i];
              i -= 1;
          }
          A[i+1] = key;
      }
  }
  
  int main()
  {
      int Asize = 0;
  
      cout &lt;&lt; "Hello. \nPlease enter a number value for the insertionSort Array size and then hit enter: " &lt;&lt; endl;
      cin &gt;&gt; Asize;
  
      int A[Asize];
  
      char Atype;
  
      cout &lt;&lt; "There are three ways to order your inserstionSort array; \nb - for best case \nw - for worst case \na - for average case" &lt;&lt; endl &lt;&lt; "Which type do you desire for this array? \nPlease enter 'b', 'w', or 'a': " &lt;&lt; endl;
      cin &gt;&gt; Atype;
  
      if (Atype == 'b')
      {
          cout &lt;&lt; "You have chosen type b." &lt;&lt; endl;
      }
  
      else if (Atype == 'w')
      {
          cout &lt;&lt; "You have chosen type w." &lt;&lt; endl;
      }
  
      else if (Atype == 'a')
      {
          cout &lt;&lt; "You have chosen type a." &lt;&lt; endl;
      }
  
  
      cout &lt;&lt; "Terminate Program" &lt;&lt; endl;
  }
  </code></pre>