You are here:

C++/dynamic allocation



How are you?
I know how to declare dynamically an array of objects of class MyClass:

MyClass **array=new MyClass *[1000];

But how could I declare a 2-dimensional array dynamically like that. The following won't work:
MyClass **array=new MyClass *[1000][1000];
What would the correct syntax be?


Hello Andres, thank you for the question.

Since you want a 2D array of pointers, I think that would need to be declared as a triple pointer. However, I've never declared one before, so I'm not sure if it'll work.

Try this:

MyClass ***array = new MyClass* [1000][1000];

And see if that works.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.

[an error occurred while processing this directive]