I want to do something like:
int a[][]; // I know this code won't work, its to demonstrate what I want to do
void func(int n, int m){
a = int[n][m];
}
that is, initialise a global array whose size depends on function input. If this array was local, it would be a trivial case, but I don't know how to do this in the case shown above. Any help would be very useful!
std::vectorunder the hood. That gives you the best performance and ease of use.std::vectorto handle that for you.aa pointer into an array of pointers instead of an array of arrays. But initializing it and cleaning it up get a bit tricky, especially considering exception safety.