home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- From: nikki@trmphrst.demon.co.uk (Nikki Locke)
- Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
- Subject: Re: Covariant Types in Derived Classes
- Distribution: world
- References: <VKE52M@netmbx.netmbx.de>
- Organization: Trumphurst Ltd.
- Lines: 55
- Date: Fri, 24 Jul 1992 19:22:08 +0000
- Message-ID: <712030928snx@trmphrst.demon.co.uk>
- Sender: usenet@gate.demon.co.uk
-
- I am one of those who view RTTI with suspicion. I have no objection to its
- inclusion in the language, but I hope it doesn't encourage a rash of
- Smalltalk programming, or the absolutely horrible switch(typeof(thing)) !
-
- In article <VKE52M@netmbx.netmbx.de> jrobie@netmbx.netmbx.de (Jonathan Robie) writes:
-
- > maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >
- > >>If I want a generic print function that can handle all types as though they
- > >>were basic types, then this print function must know the location and type
- > >>of each member, and also the name if the function is to be particularly
- > >>useful.
- >
- > > Such a utility function would be useful for debugging only.
- > >Yes, to do it you would need RTTI.
- >
- > Not so. A report generator might start by showing me the default
- > printout for an object. I can grab fields with my mouse and move
- > them around or delete them.
- >
- > A user interface tool might allow me to do something similar by providing
- > me with a default, editable window.
- >
- The report generator and the user interface tool does not _require_ RTTI.
- The objects to be displayed/reported on should return a Collection of field
- specifiers from a virtual function. These field specifiers can then be
- placed on a menu for user selection and placement. The field specifier
- will contain virtual functions to format, display, validate and set the
- value of each field. A generic user interface object can then be
- constructed to use these methods for displaying and/or editing the field.
-
- In any case, how does RTTI help ? You have a tool which will allow the
- user to create an input screen for any arbitrary object. How will knowing
- the class of the object to be displayed help ? What you really need to
- know is how to display/edit each property of an object of that class.
-
- A debugger does, of course, require RTTI. At least one C++ debugger
- actually uses RTTI info placed in the executable by the compiler to
- identify the dynamic type of objects. However, this information IS NOT
- ACCESSABLE TO THE PROGRAMMER.
-
- The only use I can see for RTTI is downcasting. The only places where I
- have found it expedient to do downcasting are in efficient implementations
- of Collection templates. I also feel very uncomfortable about it, as I
- know my Collections are not really safe - I should fix this by making my
- base collection class publicly read-only (by making all the non-const
- members protected), but I haven't yet.
-
- I haven't properly got to grips with mixins yet, but I have a glimmer of
- understanding that suggests that they might be used to solve many of the
- other problems which tempt you to use downcasting.
- ---
- Nikki Locke | | nikki@trmphrst.demon.co.uk
- Trumphurst Ltd. | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
- PC and Unix consultancy | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
-