Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!mips!daver!tscs!tct!chip From: chip@tct.com (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Re: typesafe downward casting Message-ID: <28007BC8.D71@tct.com> Date: 8 Apr 91 14:18:47 GMT References: <1991Apr2.161809.16952@kodak.kodak.com> <27FA1EC4.511C@tct.com> <1991Apr5.150148.21840@kodak.kodak.com> Organization: Teltronics/TCT, Sarasota, FL Lines: 27 According to cok@islsun.Kodak.COM (David Cok): >I am certainly looking forward to having an environment that supports >templates (no such luck here yet), and think it will do great things >for reusing implementations of Lists, etc., but I don't think it is a >replacement for inheritance. That's a straw man; no one has suggested otherwise. >If you use inheritance simply to provide a new implementation of a class, you >can keep manipulating the Base* values, and never need to deal with the >Derived class at all except to state in a declaration which derived class to >use, e.g. List* list = new MySpecialListImplementation. That's my most common use. >But another use of inheritance is to add functionality to an existing class by >deriving from it. Now virtual functions which returned Base* will still >return Base* in the derived class -- so I cannot help losing the object's >static type. In this context one must either have contravariance on the >return type of virtual functions or type-safe down casting ... Or (another choice): modify the base class for the added functionality (add a do-nothing virtual function, etc). That's my choice. -- Brand X Industries Custodial, Refurbishing and Containment Service: When You Never, Ever Want To See It Again [tm] Chip Salzenberg ,