I want to have a function which takes a positive integer, then declares an array, initializes it and print it. The following code works with a GCC compiler but it does not work with an MSVC compiler. I get the error
Error (active) E0028 expression must have a constant value. The value of parameter "Length" (declared at line 5) cannot be used as a constant
- What is a nice way to do this with an MSVC compiler? and
- Is there any nice reason for this difference?
My code:
#include <iostream>
using namespace std;
void Print(const int Length)
{
int Array[Length];
for (int i = 0; i <= Length - 1; i++)
{
Array[i] = i;
cout << Array[i];
}
}
int main()
{
const int L = 5;
Print(L);
return 0;
}