home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!timp
- From: timp@extro.ucc.su.OZ.AU (Tim Posney)
- Subject: Re: Need help implementic data structures of generic objects
- Message-ID: <timp.724484167@extro.ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: Sydney University Computing Service, Sydney, NSW, Australia
- References: <1992Dec10.114636.16861@ucc.su.OZ.AU> <1992Dec11.233253.27540@informix.com> <MATT.92Dec11162629@physics.berkeley.edu> <1992Dec13.002551.778@informix.com>
- Date: Wed, 16 Dec 1992 05:36:07 GMT
- Lines: 46
-
- cshaver@informix.com (Craig Shaver) writes:
-
- [Stuff deleted]
-
- >It is obvious to me that you have a virtual function in the base class for
- >all functions that you need to use when dealing with 'Objects'.
-
- This is a really poor,
- At the time you declare Object you need to come up with all the
- functions that an Object will support else you cannot write generic
- code, and worst will have to rebuild anything that refereces Object.
- Or you will have to downcast Object * things to derived classes.
- It is bad form to 'downcast objects',
- i.e. ptr = (Derived_From_Oject *) Object_ptr.
- since you then lose type checking at compile time.
-
-
- The obvious solution is to use Templates, it is precisely for this type
- of problem that they were developed. They are compile check safe
- and do not require extra code.
-
- >If you use a function on a class that is only restricted to a certain
- >sub-tree of your inheritance structure, then you know what you are using,
- ********************************
- Surely in the OOP world we can write code that will work correctly even
- if the user does not know what he is doing. This is the whole point.
- >ergo, you should have used that type instead of 'Object'.
- Surely one can write generic container classes that will work on
- Objects today, and Mooses tomorrow, without re-coding (even of headers)
- and without re-compiling.
-
- >Please; in all of the above, correct me if I have been technically
- >wrong, and then explain your philisophical counter point to the
- >use of inheritance.
-
- I agree that inheritance is great but do not use the languague features
- incorrectly. Smalltalk and C++ are DIFFERENT, they approach the same
- problems differently. What is a good solution in Smalltalk (Object etc)
- is a bad solution in C++. It is possible to write completely generic
- container classes using templates, and that is the 'correct' solution
- for C++
-
-
- tim posney
-
-
-