Defining a constant/declaring an array
<p>I am trying to declare two arrays, one 2D and one 1D. I know the dimensions need to be const values. So the const value is assigned from the return value of a function call. That goes well, but when I use the derived value to declare the array, COMPILE errors! WHY???</p>

<p>Here is my code:</p>

<pre><code>int populateMatrixFromFile(string fname) {
std::ifstream fileIn;
int s = determineDimensions(fname);  // return value  (CONST INT)
const int size = s;                  // assign to const

cout &lt;&lt; "Value returned from determineDimensions(): " &lt;&lt; size &lt;&lt; endl;

if (size &gt; 10){
    cout &lt;&lt; "Maximum dimensions for array is 10 rows and 10 columns. Exiting" &lt;&lt; endl;
    return 1;
}

fileIn.open(fname.c_str(), ios::in); //opened for reading only.

float aMatrix[size][size];  // ERROR
float bMatrix[size];        // ERROR
</code></pre>

<p>BUT it works here:</p>

<pre><code>    // assign the pth row of aMatrix to temp

    const int alen = sizeof (aMatrix[p]) / sizeof (float);
    float temp[alen];                                    // WORKS!!!

    for (size_t i = 0; i &lt; alen; i++) {
        temp[i] = aMatrix[p][i];
    }
</code></pre>

<p>Thanks for all help.</p>
