Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpda!hpcupt1!thomasw From: thomasw@hpcupt1.cup.hp.com (Thomas Wang) Newsgroups: comp.std.c++ Subject: Re: Re: Dynamic type loss considered harmless Message-ID: <68950001@hpcupt1.cup.hp.com> Date: 6 Mar 91 02:13:33 GMT References: <27CD13B1.649B@tct.uucp> Organization: Hewlett Packard, Cupertino Lines: 33 / hpcupt1:comp.std.c++ / chip@tct.uucp (Chip Salzenberg) / 8:30 am Mar 4, 1991 / It is possible to abuse the type tag feature. But let me describe to you a situation typing information is required. Suppose we have an 'array' library that always operates on objects of class 'object'. Now suppose you have a class called 'person'. You put some 'person' objects into an array variable. A problem that will come up when one tries to retrive the objects out of the array. A 'person*' that was put into the array will come out as 'object*'. Is it safe to cast from 'object*' to 'person*'? Conceptually speaking, it is safe to do the casting iff the object isa 'person*'. (note 1) This question cannot be answered without knowing some run-time typing information. Assuming you can do the cast, then you can call member functions of 'person', such as ((person*) obj)->walk(). The designer of the 'object' class have no way to know there will be a 'person' class later, so defining walk() function as base virtual from the 'object' class is really not a solution. So far, the only good use of type information I have found is the example above. Seems in all other cases, virtual functions can serve better than explicitly looking at runtime typing information. (note 1) C++ multiple inheritance violates this assumption, but that's another story... -Thomas Wang (Everything is an object.) wang@hpdmsjlm.cup.hp.com thomasw@hpcupt1.cup.hp.com