Article View: cs.questions
Article #2Re: Dynamic Multidimensional Array Allocation in C++
From: 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
Technical Details
Message-ID:
<C0Cw7r.72t@dcs.ed.ac.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!uknet!edcastle!dcs.ed.ac.uk!tkReferences:
<C0C68I.MA7@dcs.ed.ac.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!uknet!edcastle!dcs.ed.ac.uk!tk From: tk@dcs.ed.ac.uk (Tommy Kelly) Newsgroups: cs.questions,comp.lang.c++ Subject: Re: Dynamic Multidimensional Array Allocation in C++ Message-ID: <C0Cw7r.72t@dcs.ed.ac.uk> Date: 5 Jan 93 01:02:14 GMT References: <C0C68I.MA7@dcs.ed.ac.uk> Sender: cnews@dcs.ed.ac.uk (UseNet News Admin) Reply-To: tk@dcs.ed.ac.uk (Tommy Kelly) Organization: Laboratory for the Foundations of Computer Science, Edinburgh U Lines: 18