home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12937 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.2 KB  |  39 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!UB.com!igor!thor!rmartin
  2. From: rmartin@thor.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: a question about '[ as an operator
  5. Message-ID: <rmartin.714865940@thor>
  6. Date: 26 Aug 92 21:52:20 GMT
  7. References: <J5e4PB1w165w@toz.buffalo.ny.us>
  8. Sender: news@Rational.COM
  9. Lines: 28
  10.  
  11. cyberman@toz.buffalo.ny.us (Cyberman) writes:
  12.  
  13. >1: is it possible to specify the '[ as an operator?
  14.  
  15. No, but you can specify '[]' as an operator.
  16.  
  17. >2: HOW?  I'm confused about this
  18.  
  19. class X
  20. {
  21.   public:
  22.     int operator[] (int index);  // the return value and argument 
  23.                                  // don't need to be ints. They can be
  24.                                  // anything at all.
  25. };
  26.  
  27. >3: if so can they be doubled scripted ie  [X][Y]
  28.  
  29. Yes, but this is tricky.  You have X::operator[] deal with the first
  30. subscript, and then return an instance of class Y.  You then have
  31. Y::operator[] handle the second subscript.
  32.  
  33.  
  34. --
  35. Robert Martin                        Training courses offered in:
  36. R. C. M. Consulting                       Object Oriented Analysis
  37. 2080 Cranbrook Rd.                        Object Oriented Design
  38. Green Oaks, Il 60048 (708) 918-1004       C++
  39.