home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18975 < prev    next >
Encoding:
Text File  |  1993-01-11  |  990 b   |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!grebyn!daily!dougw
  3. From: dougw@grebyn.com (Doug Worthington)
  4. Subject: What is wrong with this, a simple question 
  5. Message-ID: <1993Jan12.003246.14658@grebyn.com>
  6. Organization: Grebyn Timesharing
  7. Date: Tue, 12 Jan 1993 00:32:46 GMT
  8. Lines: 54
  9.  
  10. Here is a snipt of code, why doesn't this work
  11.  
  12. .h file
  13. ----------
  14. class foobar
  15. ....
  16. public:
  17.     char operator [] (int index);
  18. ....
  19.  
  20. .cc file
  21. -----------
  22. ....
  23. char foobar::operator [] (int index)
  24. {
  25.     .....
  26. }
  27.  
  28. source file This example works.
  29. -----------
  30.  
  31.     foobar fooBarThing();
  32.  
  33.     cout << fooBarThing[1];
  34.  
  35. source file This example DOESN'T work
  36. ---------
  37.     
  38.     foobar *fooBarThing();
  39. /* allocat the foobar object */
  40.  
  41.     count << fooBarThing[1];
  42.  
  43. Why does declaring the objecty as a pointer change the use of the index
  44. member function.  The [] operater function isn't even called in the
  45. second example.
  46.  
  47. Thanks for the help
  48.  
  49. dougw
  50. dougw@grebyn.com
  51.  
  52. P.S.  please respond to me and not the net if you can.
  53.  
  54.     
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.