Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!deccrl!news.crl.dec.com!shlump.nac.dec.com!pa.dec.com!decwrl!lattanzi From: lattanzi@decwrl.dec.com (Len Lattanzi) Newsgroups: comp.lang.c++ Subject: Re: asking an object for its type Message-ID: <1991Feb19.191731.4137@pa.dec.com> Date: 19 Feb 91 19:17:31 GMT References: <1991Feb19.000449.22255@gpu.utcs.utoronto.ca> <607@taumet.com> <65451@brunix.UUCP> Sender: news@pa.dec.com (News) Organization: DEC Western Software Lab Lines: 38 In article <65451@brunix.UUCP> sdm@cs.brown.edu (Scott Meyers) writes: :In article <607@taumet.com> steve@taumet.com (Stephen Clamage) writes: :| >imagine a database query: :| :| > "from the list of shapes, show me all the circles of diameter > 30" :| :| All you have to do is make a virtual function diameter() for all Shapes. :| A function which expects to operate on a class of type Shape may :| reaonably expect all the functionality of Shape to be present. It may :| not reasonably expect specific behaviors of classes derived from Shape :| to be present. : :This is of course the right way to go, and most of the time it is a :workable solution, but there are times when it simply won't do. : :I personally believe that we need language support for this kind of thing, :but it would be so prone to abuse and Bjarne is so dead-set against it that :I don't hold out much hope that it will be seriously considered by the ANSI :committee. Instead, I think that compiler vendors will add proprietary :support for it, and there will be a market free-for-all. I know that at :least one compiler vendor already has implemented such a facility for :getting type information at runtime. : :The bottom line is that virtual functions are wonderful things and can :almost always be used to achieve what you want, but there are times when :you truly *do* need to get type information as you run. : :Scott This is especially true for expanding library interfaces. I wished for an "interactive(istream&)" predicate but had my hands tied. I could either compare pointer-to-members to guess at class type (boo! hiss!) or use iostream state variables to record this information. Something like a property-list per object is probably the desire of most lisp hackers. \ Len Lattanzi (Migration Software Systems Ltd 408 452 0527)