home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!news2me.ebay.sun.com!exodus.Eng.Sun.COM!France.Sun.COM!obourdon
- From: obourdon@France.Sun.COM (Olivier Bourdon - Sun ICNC)
- Newsgroups: comp.lang.c++
- Subject: Generic types
- Date: 28 Aug 1992 14:03:06 GMT
- Organization: SunConnect
- Lines: 56
- Distribution: world
- Message-ID: <l9scgqINNh7u@exodus.Eng.Sun.COM>
- NNTP-Posting-Host: sunalps.france.sun.com
-
- Let's assume I have two different types of objects (classes)
- //-------------------
- class complex {
- public:
- int i,j;
- ...
- void Print();
- };
- //--------------------
- class string
- public:
- char *str;
- ...
- void Print();
- };
-
- and I also have a double linked list
- //-----------------
- class list {
- void *element;
- list *next, *prev;
- void Print();
- };
-
- then I woul like to do something like :
- void list::Print() {
- while (this->next!=NULL)
- this->elem->Print();
- ...
- }
-
- I know that it does not work AT COMPILE TIME because the Print function is not
- a member function for void * type. It seems like I could create sur-classes
- of list by removing the element field in the list class and adding :
- class stringlist {
- string *element ;
- ...
- };
-
- but then I have to write 2 times the EXACTLY SAME CODE once for
- stringlist::Print and the other one for complexlist::Print
- and I would like to have only one piece of code so that if I have to
- modify it I do it only at one place
-
- Thanks for any idea
- Olivier
-
- --
- +---------------------------------+-----------------------------------+
- |Olivier BOURDON | Address : SUN MICROSYSTEMS |
- |E-Mail : obourdon@France.Sun.COM | International Center for|
- |Tel : +33 76 41 42 19 | Network Computing |
- |Fax : +33 76 41 42 41 | 32 av du Vieux Chene |
- | | 38 240 Meylan Zirst |
- |member of OSI development team | FRANCE |
- +---------------------------------+-----------------------------------+
-