array of class

hi.
I can not find a satisfactory explanation for the dynamic memory management with an array of class.
can anyone help me?

I know this but don't understand why "pointer to pointer"
1
2
3
4
5

myclass **mc = new mc*[5];

for (int i = 0; i < 5; ++i)
      mc[i] = new mc[6];     


Thx
First of all this code is invalid

1
2
3
4
myclass **mc = new mc*[5];

for (int i = 0; i < 5; ++i)
      mc[i] = new mc[6];


Should be

1
2
3
4
5
myclass **mc = new myclass*[5];

for (int i = 0; i < 5; ++i)
      mc[i] = new myclass[6];


If you are allocating an array dynamically then operator new returns pointer to the first element of the array,

As in your example the element type of array new myclass*[5] is myclass* then the pointer to an object of type myclass* will be myclass**
it is true. I found the code in http://www.cplusplus.com/forum/general/2609/ ... but I copied the wrong one.

in this link, the user asked for the dynamic memory for an array of class 2D. but for a 1D array, the same holds true? thanks for the reply
Topic archived. No new replies allowed.