home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18689 < prev    next >
Encoding:
Internet Message Format  |  1993-01-05  |  1.0 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!edcastle!dcs.ed.ac.uk!tk
  2. From: tk@dcs.ed.ac.uk (Tommy Kelly)
  3. Newsgroups: cs.questions,comp.lang.c++
  4. Subject: Re: Dynamic Multidimensional Array Allocation in C++
  5. Message-ID: <C0Cw7r.72t@dcs.ed.ac.uk>
  6. Date: 5 Jan 93 01:02:14 GMT
  7. References: <C0C68I.MA7@dcs.ed.ac.uk>
  8. Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
  9. Reply-To: tk@dcs.ed.ac.uk (Tommy Kelly)
  10. Organization: Laboratory for the Foundations of Computer Science, Edinburgh U
  11. Lines: 18
  12.  
  13. In article <C0C68I.MA7@dcs.ed.ac.uk> tk@dcs.ed.ac.uk (Tommy Kelly) writes:
  14. >How do I implement a dynamically configurable two dimensional array in C++?
  15. >
  16. >For one dimension its easy, but doing:
  17. >
  18. >my_type *my_type_var = new my_type[a][b];
  19.  
  20. What I'm doing at the moment is explicitly creating a vector of vectors like:
  21.  
  22.     My_type **my_type_var = new My_type*[a];
  23.     for(int i=0; i<b; i++) {
  24.           my_type_var[i] = new My_type[b];
  25.     }
  26.  
  27. I can then access the array my_type_var[a][b] as normal.
  28. But it seems kinda inelegant.  Maybe I expect too much from C++...
  29.  
  30. tk
  31.