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

TH>I want to overload the '[' to facillitate 2-dimentional arrays, ie.
DM>It's actually the [] operator, but...
Yes, I know. But the '[' is the active ingriedent.
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...???
DM>You basically need to have a class that holds arrays of pointers.
This is the way they showed us in school, but I don't think that is
an effient implementation.
DM>table[x] will be a pointer to table_type.  Which will be a
DM>single-subscript array.  So if you seperate this:
DM>table_type* t = table[x];
DM>thisVal = t[y];
DM>You can see this works.  So, get rid of the temp var 't'.
Hmm. Didn't work...
Maybe you can post a complete example?
___ Blue Wave/QWK v2.12
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 530-893-8079 * (1:119/88)

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™.