Path: utzoo!attcan!uunet!decwrl!bacchus.pa.dec.com!shlump.nac.dec.com!peewee.enet.dec.com!heintze From: heintze.peewee.enet.dec.com (Sieg Heintze) Newsgroups: comp.lang.c++ Subject: Multidimensional Arrays accessed with [] operator Summary: How to implement multidimensional Arrays Keywords: Arrays, [] operator Message-ID: <13060@shlump.nac.dec.com> Date: 3 Jul 90 17:19:22 GMT Sender: newsdaemon@shlump.nac.dec.com Organization: Digital Equipment Corporation Lines: 39 During Spring Semester, I was simulating the write path of a magnetic-optical storage (MO) disk. I needed a five dimenensional array of floats whose dimensions would be determined at run time. I was also determined to access the elements with the [] operator regardless of whether I was in a function or not! I wanted to create a special array class and overload the [] operator. As you may know, there is a serious problem with C and the default array syntax for C++. I refer you to page 120 of Stroustrup's "the C++ Programming Language" where he says you cannot pass arrays, you can only pass pointers and inside the recieving subprogram you have to compute your own offsets. Even Bjarne (in the comments) says that this is obscure! Someone kindly gave an example of using the [] operator to access a pseudo array. This what was done was to use [] to access an array of pointers. So for each successive dimension, you have another array of pointers. Each array of pointers is contained an a class that also holds the bounds for that row or column. Well this was very nice and even pratical for two dimensional arrays. But I was afraid to try it with a five dimensional pseudo array! The redundant overhead would be staggering! How can I efficiently overload [] for a five dimensional pseudo array. Better yet, how can I efficiently overload [] for a five dimensional real array (ie, an contiguous array that does not use pointers to find a element given the row and column). Incidently, for my simulation, I gave up on overloading [] and just used the features of C to access entity declared as "float**** modisk;". This did not, of course, have the bounds checking I wanted. heintze@genral.enet.dec.com Digital Equipment Corporation 1110 Chapel Hills Drive CXN2-2/35 Colorado Springs, CO 80920-3995 719-260-2184