Thread View: gnu.g++
2 messages
2 total messages
Started by "Naoki Saito Ext. 5471", GEO-002
Wed, 28 Jun 1989 16:38
fetching the multi-dimensional array classes
Author: "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
g++ and Sunview (I forgot my .sig)
Author: Sho Kuwamoto
Date: Fri, 30 Jun 1989 23:54
Date: Fri, 30 Jun 1989 23:54
11 lines
888 bytes
888 bytes
I forgot to include my .signature last time (I think) so here it is. Any help *mailed* to me would be greatly appreciated, since the coonnection between LA and Purdue died no less than 10 times in the proces of posting the prev. article and this followup. Thank you for your help. -Sho address: sho@risc.com <-- NOTE: Not the same as above. -- address: sho@risc.com <-- NOTE: Not the same as above.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads