Alright. I've been programming a game in C++ for a while now, and I can not find the solution to this. I want to declare an array with three dimensions using the new keyword, since its dimensions will vary from each object. Also, the elements in the array are pointers to SDL_Surfaces. I have not yet found a way to do this. Any help is appreciated.
FYI, I did search. I only make forum posts as last resorts.
So that is the only way to allocate a dynamic array of pointers? If there is a better way, please tell me before I go and do something stupid. But I really can't see any other way to do this.
To my knowledge, yes that is the only way. Are you sure you need a 3D array though? Can you do it via 2D array with a container class? or perhaps Map of lists?
I guess the question is what are you trying to accomplish and is 3d array the only option?
No, this is the only way to allocate 3d arrays. What you can do is to use a single dimensional array, and think about it as a continuously allocated 3d array.
Actually, that does give me an idea. One of the array dimensions is constant, so ill use that as a "standard" array, and just have 2D arrays within those elements (which is what I was aiming for in the first place, except I won't use the heap for the first dimension). I do know that a linked list would be horribly inefficient. I think I'll be able to handle this way just fine, if I use the destructor correctly.
@R0mai:
I considered this, but I didn't want to confuse myself when trying to access arrays. The initialization and destruction might be simpler, but I don't want to have to refer to its elements that way.
I think I can mark this thread as solved now. Thanks for the help.