Dynamic Allocation of Multi-Dimensional Array (Simple Question)
Author Message
Dynamic Allocation of Multi-Dimensional Array (Simple Question)

How do you allocate a Multi-Dimensional Array in C++ dynamically?
Using MS Visual C++ 5.0;

For a single dimension array this works

//global ;
int *array ;

//... in main()
int size = 20  ;
array = new int[size] ;

But this syntax doesn't work for more dimensions.
What is the solution for 2 or 3 dimensions?

//global ;
int **array ;

//... in main()
int sizex = 20  ;
int sizez = 60 ;
array = new int[sizex][sizez] ;

// generates error
// cannot convert from 'int(*)[1]' to 'int**'

Wed, 14 Nov 2001 03:00:00 GMT
Dynamic Allocation of Multi-Dimensional Array (Simple Question)
One way to find out is to ask at comp.lang.c++ (this is comp.lang.c) which
is where discussions focus on Standard C.
Regards,
Greg Martin
Quote:

>How do you allocate a Multi-Dimensional Array in C++ dynamically?
>Using MS Visual C++ 5.0;

>For a single dimension array this works

>//global ;
>int *array ;

>//... in main()
>int size = 20  ;
>array = new int[size] ;

>But this syntax doesn't work for more dimensions.
>What is the solution for 2 or 3 dimensions?

>//global ;
>int **array ;

>//... in main()
>int sizex = 20  ;
>int sizez = 60 ;
>array = new int[sizex][sizez] ;

>// generates error
>// cannot convert from 'int(*)[1]' to 'int**'

Wed, 14 Nov 2001 03:00:00 GMT
Dynamic Allocation of Multi-Dimensional Array (Simple Question)

Quote:

>How do you allocate a Multi-Dimensional Array in C++ dynamically?
>Using MS Visual C++ 5.0;

You'll need to ask is a newsgroup where discussion of C++ is appropriate
(not to mention where C++ experts hang out). Try comp.lang.c++.

--
-----------------------------------------

-----------------------------------------

Wed, 14 Nov 2001 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages