Thread View: cs.questions
2 messages
2 total messages
Started by Tommy Kelly
Mon, 04 Jan 1993 15:41
Dynamic Multidimensional Array Allocation in C++
Author: Tommy Kelly
Date: Mon, 04 Jan 1993 15:41
Date: Mon, 04 Jan 1993 15:41
11 lines
671 bytes
671 bytes
How do I implement a dynamically configurable two dimensional array in C++? For one dimension its easy, but doing: my_type *my_type_var = new my_type[a][b]; doesn't seem to work. thanks for any help. tk
Re: Dynamic Multidimensional Array Allocation in C++
Author: Tommy Kelly
Date: Tue, 05 Jan 1993 01:02
Date: Tue, 05 Jan 1993 01:02
18 lines
1070 bytes
1070 bytes
In article <C0C68I.MA7@dcs.ed.ac.uk> tk@dcs.ed.ac.uk (Tommy Kelly) writes:
>How do I implement a dynamically configurable two dimensional array in C++?
>
>For one dimension its easy, but doing:
>
>my_type *my_type_var = new my_type[a][b];
What I'm doing at the moment is explicitly creating a vector of vectors like:
My_type **my_type_var = new My_type*[a];
for(int i=0; i<b; i++) {
my_type_var[i] = new My_type[b];
}
I can then access the array my_type_var[a][b] as normal.
But it seems kinda inelegant. Maybe I expect too much from C++...
tk
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads