home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15844 < prev    next >
Encoding:
Internet Message Format  |  1992-11-06  |  1.2 KB

  1. From: kevinc@hpcc01.corp.hp.com (Kevin Collins)
  2. Date: Thu, 5 Nov 1992 18:04:18 GMT
  3. Subject: Inheritance & operator overloading
  4. Message-ID: <1000009@hpcc01.corp.hp.com>
  5. Organization: the HP Corporate notes server
  6. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!scd.hp.com!hpscdm!hplextra!hpcc05!hpcc01!kevinc
  7. Newsgroups: comp.lang.c++
  8. Lines: 42
  9.  
  10.  
  11. I have a child of an array class that inherits an overloaded operator=.
  12. I need to add some functionality to that operator= then I would like to
  13. call the *inherited* operator=.  What is the syntax for this?  I've
  14. done it many times for "normal" functions ... 
  15.  
  16. Thanks,
  17.  
  18. Kevin
  19. -----------------------------------------------
  20.  
  21. template <class Type> 
  22. class baseArray {
  23.  
  24.   public :
  25.  
  26.   Type&  operator[] (int i);
  27.  
  28. }
  29.  
  30. template <class Type> 
  31. class child : public  Block<Type> {
  32.  
  33.   public :
  34.  
  35.    Type&  operator[] (int i);
  36.  
  37. }
  38.  
  39.  
  40. template <class Type>
  41. Type& child<Type>::operator[] (int i) {
  42.  
  43.    // do something of added value here ...
  44.  
  45.    return a call of inherited operator[] call here, meaning something like :
  46.                     ---------
  47.    
  48.    return (*this)[i];  // but NOT this since this will create an infinite loop.
  49.  
  50. }
  51.  
  52.