Path: chuka.playstation.co.uk!news From: daniel@reichardt.ch (Daniel Hartmeier) Newsgroups: scea.yaroze.freetalk Subject: Re: Net Yaroze C++ Examples Date: Sat, 29 May 1999 09:08:40 GMT Organization: Reichardt Informatik AG Lines: 43 Message-ID: <3750aa84.6218571@news.playstation.co.uk> References: <374c6512.1232873@news.scea.sony.com> <374E06E4.5D701DDC@identicalsoftware.com> <37505449.1115333@news.playstation.co.uk> <7imgt2$3vd2@scea> NNTP-Posting-Host: dial-in-68.magnet.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Newsreader: Forte Agent 1.5/32.451 On Fri, 28 May 1999 09:44:32 -0700, "Steve Spiller" wrote: > Just do it the old fashioned way! > > typedef enum { > ntTile, > ntEnemy, > ntLevel > } NODETYPE; > > typedef struct _tagNode { > NODETYPE nNodeType; > void *pItem; > struct _tagNode *pNext; > } NODE, *LPNODE; > > Then you just create structures for holding all your different node types > and when you walk down the list you cast the void pointer to whatever type > the nNodeType indicates. Voila! Generic linked list in C. :) Your example will create less code than template struct Node { T *item; Node *next; }; as the C++ compiler will produce separate code for each type T used. But use of the template establishes the rule that a list of type Node will only contain items of the same type T (or do you want to have mixed lists?), and removes the need for run-time checks of the node type, making the application smaller, faster and safer. Regards, -- Daniel Hartmeier PGP 6A3A7409 ICQ# 12742482 "The woods are lovely, dark and deep. But I have promises to keep, And lines to code before I sleep, And lines to code before I sleep."