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  
 
 [ 3 post ] 

 Relevant Pages 

1. Multi-dimensional array using dynamic memory allocation

2. Dynamic Memory Allocation For Multi-Dimensional Arrays

3. Multi-dimensional array using dynamic memory allocation

4. Multi-dimensional array memory allocation.

5. Multi-dimensional array memory allocation.

6. Multi-dimensional array allocation - the *easy* way.

7. Run-time memory allocation for multi-dimensional arrays

8. Dynamic allocation of 2-dimensional array

9. Dynamic allocation and reallocation of two dimensional arrays

10. Dynamic allocation 2 dimensional array

11. Dynamic memory allocation of two dimensional arrays

12. Dynamic Allocation of 2-Dimensional Arrays

 

 
Powered by phpBB® Forum Software