I want to do something like:
const int N = 10;
void foo (const int count)
{
int (* pA) [N][count] = reinterpret_cast<int(*)[N][count]>(new int[N * count]);
...
}
But my compiler (VS2010) doesn't want to do it:
error C2057: expected constant expression
error C2540: non-constant expression as array bound
Such a way he expresses his dissatisfaction with the count
.
I know, how it can be worked around by implementing a slightly different way. But I just don't get, why does C++ forbid me to use this way. I understand, why C++ needs to know on-stack arrays size at compile time (to allocate array memory). But why the same restrictions are necessary with respect to pointers to array (after all, pointer is just a tool to work with that allocated memory)?