Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!gatech!gt-eedsp!baud From: baud@gt-eedsp.UUCP (Kurt Baudendistel) Newsgroups: comp.lang.c++ Subject: Re: Declaration of multi-dimensional arrays. Message-ID: <430@gt-eedsp.UUCP> Date: 6 Sep 88 15:05:54 GMT References: <8809040943.AA28707@rice-chex.ai.mit.edu> Reply-To: baud@gt-eedsp.UUCP (Kurt Baudendistel) Organization: School of Electrical Engineering, Ga. Tech, Atlanta, GA 30332 Lines: 56 In article <8809040943.AA28707@rice-chex.ai.mit.edu> tmb@ganymede.UUCP discusses Doug Schmidts comments on the [] operator taking only one argument and how this jives with easily implementable multi-dimensional arrays. it is possible to implement multi-dimensional arrays using the ``normal'' [] notations. to do this, you have to implement, dynamically, the array dimensionality: md_array A(3); // declare 3-d array A[0] -> returns first 2-d array of A type is ``2-d array'' A[0][1] -> return second 1-d array of previous type is ``1-d array'' A[0][1][2] -> returns third element of previous type is ``scalar'' (perhaps, double) for me, this is just too inefficient. i use the following notation in a vector (1-d) / matrix (2-d) implementation: doubleVec a(4); // declare 4-element, 1-d array // of doubles a(0) * -> returns first element of vector a type is double a(0,1) -> returns vector consisting of elements 0-1 of a type is doubleVec doubleMat A(4,4); // declare 4x4 element, 2-d array // of doubles A(0,0) -> returns first element of array A type is double A(1) * -> returns vector consisting of second row of A type is doubleVec i could, of course, have used the [] notation for the *'d example lines, but i chose to use just the () notation, keeping the ``look'' and feel of vectors and matrices all their own. is this functional or operational syntax in its usage here? note also that i could have used double [] notation A[0][0] to get the first element of array A, but for efficiency reasons, i chose to use a single level operation of A(0,0) rather that the two-level operation required to use [] twice. you can argue about the merits of [] notation over () notation and whether or not to allow multiple arguments to [], but i think that each has its place. -- Kurt Baudendistel [GRA McClellan] Georgia Tech, School of Electrical Engineering, Atlanta, GA 30332 USENET: ...!{allegra,hplabs,ihnp4,ulysses}!gatech!gt-eedsp!baud INTERNET: baud@gteedsp.gatech.edu