C++: Expression must have a constant value when declaring array inside function
<p>I have looked at all the other posts with a similar topic, and none help, so please don't flag as a duplicate. </p>

<p>I am defining in <code>main()</code> a <code>const int SIZE = 20;</code>. Then, I pass this as an argument to my function, Mode:</p>

<pre><code>int* Mode(int* numbers, int &amp; mode, const int SIZE)
 {
     int occurences[SIZE];

     // Calcualte mode
 }
</code></pre>

<p>However, I get the error, <code>expression must have a constant value</code>. </p>

<p>My function call (in main) looks like this:</p>

<pre><code>int* occurencesPtr = Mode(numbersPtr, mode, SIZE);
</code></pre>

<p>With <code>SIZE</code> being defined at the beginning to the literal <code>20</code>. </p>

<p>I understand that the error is because the function's version of <code>SIZE</code> only acquires its value when the function is called (?), but I don't know how I could work around this.</p>

<p>I have even tried passing to the function a <code>const int * const SIZEPtr = &amp;SIZE</code>, but that didn't work either. Help?</p>

<p><strong>EDIT: I am <em>not</em> trying to use a variable size!! Notice that I have made <code>SIZE</code> a <code>const</code> everywhere! I just want to use that same SIZE constant to declare my array.</strong> </p>

<p>EDIT: Dynamic arrays are not what I need. I just want a normal, named, array, defined with a <strong>constant</strong> size value passed to the function.</p>