From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public From: kjhopps@mmm.com (Kevin J. Hopps) Subject: Re: What is wrong with OO ? Date: 1997/02/17 Message-ID: <33088196.68A0@mmm.com>#1/1 X-Deja-AN: 219396133 References: <5dopri$dei@news4.digex.net> <3301D875.188B@mmm.com> <33049C7C.41C6@wi.leidenuniv.nl> Content-Type: text/plain; charset=us-ascii Organization: Imation Corp. Mime-Version: 1.0 Reply-To: kjhopps@mmm.com Newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng X-Mailer: Mozilla 3.01 (WinNT; I) Date: 1997-02-17T00:00:00+00:00 List-Id: Bart Samwel wrote: > C++ does not have a 'final' keyword, so there is no way of checking that > functions will not be overridden. Omitting 'virtual' just means that a > function will not be dynamically bound. You can override non-virtual > functions, and that usually leads to very unpleasant surprises, like > mixed > use of the overridden and overriding functions on the same object. > > The C++ designer's choice of making 'virtual' explicit and 'final' > implicit > (read: not implemented) does not seem wise to me. > > The C++ use of 'virtual' is because static binding is the default for > all > functions, including functions that are redefined in descendants. But > there are almost no situations where you want to use static binding for > redefined > functions, and when you do find such a situation, you can solve the > problem > by renaming one of the functions. When you make it the default that > overridden functions are dynamically bound ('virtual') and that > non-overridden functions are statically bound, you don't have to bother > the > programmer with 'virtual' keywords at all - in this situation, the > keyword > becomes obsolete. Whether a function is statically or dynamically bound must be known at compile time. How could a compiler know whether there was somewhere some module that defined a derived class that overrides a given function? In C++ I have a choice of making functions dynamically bound or not. Whether I exercise this choice by "saying virtual" or by "not saying final" really doesn't matter to me much (except then I'd have to say "final" on all constructors, which seems like unnecessary typing). The only real difference in the two mechanisms (if I understand how "final" works) is that the absence of "virtual" does not prevent the overriding of a function in a derived class. This is a feature I might use if I had it available to me. Opinions expressed herein are my own and may not represent those of my employer.