Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!sundance!jac From: jac@gandalf.llnl.gov (James A. Crotinger) Newsgroups: comp.lang.c++ Subject: Re: How to define a List class (summary) Message-ID: Date: 13 Jun 91 15:41:03 GMT References: <350002@hpgnd.grenoble.hp.com> Sender: usenet@lll-winken.LLNL.GOV Lines: 28 Nntp-Posting-Host: sundance.llnl.gov jr@hpgnd.grenoble.hp.com (Jean-Ren BOUVIER) writes: > 2- I want to have a natural interface, i.e. being able to access my > next element in a list by using something like "list->next" or > "list->next()", the latter being easily made similar to the former by > #defining "next" to be "next()" (I know, I explicitely forbade the > use of the preprocessor :-)). I've found it much more useful to have a basic list which has no next() capability, and supplement it with a corresponding ListIterator class. This allows you to have multiple ListIterators instantiated simultaneously for the same List, which is sometimes useful. The list class which I've been using keeps a list of Object *'s. The class library implements type-safe cast operators for all classes inhereting from Object. Furthermore, if you want a specific class (say, a StringList) which doesn't require calling the cast operator explicitly all the time, you just build one from inheriting from List and ListIterator. I don't always like the indirection which is necessary when using a List of pointers. However, sans exception handling, I don't really know how to implement a robust ListIterator class which returns objects. Jim -- ----------------------------------------------------------------------------- James A. Crotinger Lawrence Livermore Natl Lab // The above views jac@moonshine.llnl.gov P.O. Box 808; L-630 \\ // are mine and are not (415) 422-0259 Livermore CA 94550 \\/ necessarily those of LLNL