Article View: gnu.g++
Article #19fetching the multi-dimensional array classes
From: "Naoki Saito Ext. 5471", GEO-002
Date: Wed, 28 Jun 1989 16:38
Date: Wed, 28 Jun 1989 16:38
33 lines
1515 bytes
1515 bytes
Hi, there! A while ago, there was some discussion on fetching method
on multi-dimensional array classes. For 1D array classes, we can define both
[i] and elem(i) to fetch the i-th element as the BOOK says. For 2D array
classes, for example, we cannot overload [][]. So instead, I'm using
elem(i,j) to fetch the (i,j)-th element. However, I recently realized that I
could use operator () to fetch the (i,j)-th element just like Fortran style,
e.g.,
Matrix A(100,100);
int i, j;
for (i = 0; i < 100; i++)
for (j = 0; j < 100; j++)
A(i,j) = .....
And the definition of the fetching method is something like this:
float& Matrix::operator(int i, int j)
{
return buf[i*cols+j]; // return without checking the index.
}
So far, it looks fine, but overloading () does effect something else in the
classes? If it does not, we can pleasantly use A(i,j) type syntax instead of
A.elem(i,j). (Of course, it is also good if we could overload [i][j], or
define [i,j])
Please give me some advise,
Regards,
Naoki Saito (saito@sdr.slb.com)
Schlumberger-Doll Research
Technical Details
Message-ID:
<8906281652.AA04026@AENEAS.MIT.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!sdr.slb.com!SAITOShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!sdr.slb.com!SAITO
From: SAITO@sdr.slb.com ("Naoki Saito Ext. 5471", GEO-002)
Newsgroups: gnu.g++
Subject: fetching the multi-dimensional array classes
Message-ID: <8906281652.AA04026@AENEAS.MIT.EDU>
Date: 28 Jun 89 16:38:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 33