TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: TIM HUTZLER
from: DARIN MCBRIDE
date: 1998-04-04 00:06:00
subject: overloaded[][]

 TH> I want to overload the '[' to facillitate 2-dimentional arrays, ie.
It's actually the [] operator, but...
 TH> thisVal = table[x][y];
 TH> Since 'table' is dynamically allocated, stactic subscripting does not
 TH> work here. Overloading a single subscript is easy, but two...???
You basically need to have a class that holds arrays of pointers.
class Table
{
 // ...
 table_type* operator[](size_t index);
};
So long as this class will hold your array of pointers, it can simply be 
returned here.  It can then also handle your memory allocation/deallocation 
for you.
table[x] will be a pointer to table_type.  Which will be a single-subscript 
array.  So if you seperate this:
table_type* t = table[x];
thisVal = t[y];
You can see this works.  So, get rid of the temp var 't'.
Good luck!
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.