Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!news.funet.fi!funic!santra!santra!Ari.Huttunen From: Ari.Huttunen@hut.fi (Ari Juhani Huttunen) Newsgroups: comp.lang.c++ Subject: Re: typesafe downward casting Message-ID: Date: 9 Apr 91 11:59:12 GMT References: <1991Apr2.161809.16952@kodak.kodak.com> <27FA1EC4.511C@tct.com> <1991Apr5.150148.21840@kodak.kodak.com> <28007BC8.D71@tct.com> Sender: news@santra.uucp (Cnews - USENET news system) Organization: Helsinki University of Technology, Finland Lines: 16 In-Reply-To: chip@tct.com's message of 8 Apr 91 14:18:47 GMT In article <28007BC8.D71@tct.com> chip@tct.com (Chip Salzenberg) writes: >>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. Is it still your choice if the base class is provided only in binary form? For example, a commercial library of classes for which you have no source code, except the header files. -- Ari Huttunen, email: Ari.Huttunen@hut.fi, phone: 90-7285944