home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!apple!apple!netcomsv!delfin.com!hades!kinne
- From: kinne@delfin.com (Kinne Strong)
- Newsgroups: comp.lang.c++
- Subject: Re: template argument as base class
- Message-ID: <1992Jul24.195032.14884@delfin.com>
- Date: 24 Jul 92 19:50:32 GMT
- References: <20204@sbsvax.cs.uni-sb.de>
- Sender: news@delfin.com (USENET on Delfin)
- Reply-To: kinne@netcom.com
- Organization: Foxglove Associates
- Lines: 42
- Nntp-Posting-Host: hades
- X-Newsreader: Tin 1.1 PL4
-
- stefan@mpi-sb.mpg.de (Stefan Naeher) writes:
- :
- : template <class T> class XYZ : public T { };
- :
- : cfront says
- : "sorry, not implemented: formal type parameter T used as base class of
- : template"
- :
- : A possible application is the implementation of data types with implementation
- : parameters, e.g., dictionary<skiplist>, dictionary<red_black_tree>, ....
-
- It sounds to me like what you really want is inheritance and virtual
- functions.
-
- class Dictionary
- {
- public:
- virtual Definition &Lookup(Word &);
- //...
- }
-
- class SkipListDictionary : public Dictionary
- {
- public:
- virtual Definition &Lookup(Word &);
- //...
- }
-
- Definition &Dictionary::Lookup(Word &w)
- {
- // Normal lookup goes here.
- }
-
- Definition &SkipListDictionary::Lookup(Word &w)
- {
- // Lookup with a skip list goes here, and has access to all of the
- // normal Dictionary:: stuff.
- }
-
- --
- Kinne Strong
- kinne@netcom.com
-