From -3686344973976248188
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8c9f1307b83ac2db
X-Google-Attributes: gidf78e5,public
From: "Cristian Georgescu" <Cristian.Georgescu@worldnet.att.net>
Subject: Re: Q: virtual functions not overridable anymore?
Date: 1997/09/08
Message-ID: <01bcb9a8$c2ed30e0$6c3474cf@worldnet.worldnet.att.net>#1/1
X-Deja-AN: 271058008
References: <01bcb109$1e790180$433574cf@worldnet.worldnet.att.net> <3404A0AE.6F7E@Eng.Sun.COM> <5uimip$l56@bgtnsc03.worldnet.att.net> <340D93AA.643A@Eng.Sun.COM>
X-Original-Date: 5 Sep 1997 03:08:59 GMT
Originator: austern@isolde.mti.sgi.com
Organization: Opal Technologies
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNBSmDky4NqrwXLNJAQGN6AIAodSsRxQgetL+XMSlLwBBTvFfPxRxeIeF YS9OeX/XVvk2dCaNg3fy66UN9siVsstQ/mE0Kcf3DGg5gqxfFvcuoQ== =1DBB
Newsgroups: comp.std.c++



> OK, I find your class useful, I add some functionality to Base,
> including some additional data members, and create class Derived.
> In order to preserve the correct semantics of "f", it must have
> additional effects on some new members of Derived. To achieve that,
> I must override f. The overriding function calls Base::f then
> performs its own actions. (In general, that is the correct way
> to override a virtual function.)
>
> Again I ask: Why?  
> 

Suppose you have a class Apple with a virtual function getColor(); then I
want to make a derived class GreenApple with getColor that will always
return Green. 
You may inherit from GreenApple, and possibly override other virtual
functions (like getPrice() ), but I do not like that you override
getColor() !

> 
> But now you add the criterion that I must not be allowed to do
> what is essential to allow my derived class to work.
> 

Making the getColor() method final (not overridable) for YellowApple class
is essential to the semantics of the class. Therefore you are not supposed
to modify it. Ideally this should not beven be a virual function. It just
is so, because YellowApple has a base class where the getColor() is
virtual.

Bootom line is:

- either the language should require you to put the "virtual keyword each
time
- or the laguage defaults a function virtual in the derived classes, but
should provide a way to terminate this!


-- 
Cristian Georgescu
_________________________________________________
    Smith Industries
    Aerospace & Defense Systems
    7-9 Vreeland Road,
    Florham Park, NJ 07932, USA.
_________________________________________________
E-mail: Georgescu_Christian@si.com      
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



