home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!UB.com!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: a question about '[ as an operator
- Message-ID: <rmartin.714865940@thor>
- Date: 26 Aug 92 21:52:20 GMT
- References: <J5e4PB1w165w@toz.buffalo.ny.us>
- Sender: news@Rational.COM
- Lines: 28
-
- cyberman@toz.buffalo.ny.us (Cyberman) writes:
-
- >1: is it possible to specify the '[ as an operator?
-
- No, but you can specify '[]' as an operator.
-
- >2: HOW? I'm confused about this
-
- class X
- {
- public:
- int operator[] (int index); // the return value and argument
- // don't need to be ints. They can be
- // anything at all.
- };
-
- >3: if so can they be doubled scripted ie [X][Y]
-
- Yes, but this is tricky. You have X::operator[] deal with the first
- subscript, and then return an instance of class Y. You then have
- Y::operator[] handle the second subscript.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-