home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11505 < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.3 KB  |  57 lines

  1. Path: sparky!uunet!sun-barr!apple!apple!netcomsv!delfin.com!hades!kinne
  2. From: kinne@delfin.com (Kinne Strong)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: template argument as base class
  5. Message-ID: <1992Jul24.195032.14884@delfin.com>
  6. Date: 24 Jul 92 19:50:32 GMT
  7. References: <20204@sbsvax.cs.uni-sb.de>
  8. Sender: news@delfin.com (USENET on Delfin)
  9. Reply-To: kinne@netcom.com
  10. Organization: Foxglove Associates
  11. Lines: 42
  12. Nntp-Posting-Host: hades
  13. X-Newsreader: Tin 1.1 PL4
  14.  
  15. stefan@mpi-sb.mpg.de (Stefan Naeher) writes:
  16. : template <class T> class XYZ : public T { };
  17. : cfront says
  18. : "sorry, not implemented: formal type parameter T used as base class of
  19. : template"
  20. : A possible application is the implementation of data types with implementation
  21. : parameters, e.g., dictionary<skiplist>, dictionary<red_black_tree>, ....
  22.  
  23. It sounds to me like what you really want is inheritance and virtual
  24. functions.
  25.  
  26. class Dictionary
  27. {
  28. public:
  29.     virtual Definition &Lookup(Word &);
  30. //...
  31. }
  32.  
  33. class SkipListDictionary : public Dictionary
  34. {
  35. public:
  36.     virtual Definition &Lookup(Word &);
  37. //...
  38. }
  39.  
  40. Definition &Dictionary::Lookup(Word &w)
  41. {
  42.     // Normal lookup goes here.
  43. }
  44.  
  45. Definition &SkipListDictionary::Lookup(Word &w)
  46. {
  47.     // Lookup with a skip list goes here, and has access to all of the
  48.     // normal Dictionary:: stuff.
  49. }
  50.  
  51. --
  52. Kinne Strong
  53. kinne@netcom.com
  54.