John Matthews wrote:
>
> --- In [email protected] <mailto:c-prog%40yahoogroups.com>, 
> Christopher Coale <chris95...@...> wrote:
> >
> > Jos Timanta Tarigan wrote:
> > >
> > > colour *col=new colour[10][10]; <-- i cant compile this line.
> > >
> > > cannot convert int(*)[10] to int*
> > >
> > You just need to typecast the "new colour[10][10]" to a "colour *".
> >
> > colour *col = (colour *)new colour[10][10];
>
> Sorry, I don't do C++, but if you needed a typecast in the equivalent
> C program, I would say you had done something wrong. Please tell me
> there's a better way :-)
>
>  
Why do you say that? It simply returns a pointer to the first element in 
the array, and from there you can access every element inside it.

int *myArray = (int *)new int[5][5];
myArray[(0 * 5) + 0] = 100;

With this way, you can use the formula "(y * cols) + x" to get to the 
element you want. Otherwise, you can use a pointer to a pointer to use 2 
subscripts.

int **box = (int **)new int[10][10];
box[0][0] = 100;



[Non-text portions of this message have been removed]

Reply via email to