Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!sdd.hp.com!hplabs!hpda!hpcupt1!thomasw From: thomasw@hpcupt1.cup.hp.com (Thomas Wang) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things ... Mostly requests for info. Message-ID: <68070004@hpcupt1.cup.hp.com> Date: 21 Jun 91 18:10:03 GMT References: <18939@prometheus.megatest.UUCP> Organization: Hewlett Packard, Cupertino Lines: 45 >From article <285E75EC.37E7@tct.com>, by chip@tct.com (Chip Salzenberg): >> According to djones@megatest.UUCP (Dave Jones): >>> while( member = (SomeType*)List_iter_next(&iter)) >> >> Aargh. >> >> This is exactly the downcast hackery that I avoid at all costs. >And that is exactly the kind of derisive pedantry that I avoid at all >costs. >Even though the above technique has proved perfectly adequate in C-code >for six years, my posting asked for a better way to do it in C++. >Do you have any suggestions, or only insults? Basically there are two camps. One camp think in order to have a list that can contain anything, type cast down facility must be provided. Another camp think type cast down is dangerous, and one should use templates instead. Although using templates is type safe. It restricts the things that can be inside the list to one type only. Some people say this is too restrictive. People counters with :"What is the last time you want more than one type of objects inside a list?" In order to have safe type down cast, three things must be provided. (1) Mechanism to determine if it is safe to do the down cast. (2) Mechanism to perform the down cast. (3) Exception handling mechanism to handle type casting error. Currently C++ does not explicitly support the three mechanisms. Programmers must roll their own thing. How this can be accomplished is disscussed here many times, so I will not repeat it. The solutions proposed all have some aspect of kluge associated with them. I personally think program re-use without type down cast is difficult. I hope that safe type down cast can be implemented in a future version of C++ compiler. -Thomas Wang (GC is the key to everything.) wang@hpdmsjlm.cup.hp.com thomasw@hpcupt1.cup.hp.com