I’m having a C2057 error (on Visual Studio 2010) and I’m not sure why. I understand that to initialize an array on the stack, the size must be known at compile time which is why you need to use a const value (at least on Visual Studio since variable length array are not permitted like in gcc). I have a const value member in my class and I define his value in the initialization list. So technically, the value is known at compile time right? I’d like to understand why it doesn’t work ? Here’s a snippet:
class Dummy
{
Dummy() : size(4096) {}
void SomeFunction()
{
int array[size]; //return C2057
//...
}
const unsigned int size;
};
Thanks
Unfortunately, this const value is not a compile time constant. You would need an enum, a static integral type, or a C++11
constexpr.Another option is to make
Dummya class template, taking a non-type parameter: