Path: utzoo!attcan!uunet!cs.utexas.edu!rice!uw-beaver!sumax!ole!powell From: powell@ole.UUCP (Gary Powell) Newsgroups: comp.lang.c++ Subject: Extensions to [] Message-ID: <1589@ole.UUCP> Date: 6 Jun 90 15:30:21 GMT Reply-To: powell@ole.UUCP (Gary Powell) Organization: Seattle Silicon Corporation, Bellevue, WA. Lines: 46 I am new to C++ but after a seminar and some play time I tried writting a class for two diminsional arrays. What I found myself wanting was a overloaded operator [][](int)(int). However my GNU g++ 1.35 compiler complains bitterly when I tried to code this. Why not use the (int,int) operator? Well I was using that for the initialization. It would seem to me that since C allows array[][] access that C++ should allow overloading of this also. With this background has there been any discussion on the overloading of [][] ....[]? And is this a reasonable extension to the language? Resons for doing this are that N'dim. arrays are a pain to pass to functions. With a class I can add the extra information for bounds checking and pass the arguement as a single pointer and let the compiler call my code to access the array. class TWO_DIM { public: TWO_DIM(int r,int c) { /* initialize */} int & operator[][](int r)(int c) { /* bound check */ return & array [r][c];} ~TWO_DIM() {delete array;} private: int *array, max_col, max_row; }; subroutine (TWO_DIM &i-arry) { i-arry[5][2] = i-arry[2][5]; // garbage code. } main() { TWO_DIM i-array(10,20); i-array[0][15] = 5; subroutine (i-array); } -- _Q _Q _Q _Q _Q_Q _Q _Q _Q /_\) /_\) /_\) /_\)/_/\\) /_\) /_\) Gary Powell /_\) _O|/O_O|/O__O|/O___O|/O_OO|/O__O|/O__O|/O__________________________________O|/O_ uunet!uw-beaver!sumax!ole!powell Seattle Silicon Corp. (206) 828-4422