From 499484139158156179
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,aa5ce7ee74d4b87c
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-07-13 02:36:56 PST
Path: bga.com!news.sprintlink.net!hookup!usc!howland.reston.ans.net!EU.net!Germany.EU.net!netmbx.de!zib-berlin.de!informatik.tu-muenchen.de!schuenem
From: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Newsgroups: comp.std.c++
Subject: Re: force the virtual keyword on virtual members
Date: 13 Jul 1994 09:35:30 GMT
Organization: Technische Universitaet Muenchen, Germany
Lines: 45
Distribution: world
Message-ID: <300ch2$c68@hpsystem1.informatik.tu-muenchen.de>
References: <2vtfd9$rht@euas20.eua.ericsson.se>
NNTP-Posting-Host: hpbroy12.informatik.tu-muenchen.de
Keywords: virtual
Originator: schuenem@hpbroy12.informatik.tu-muenchen.de


konfjo@eua.ericsson.se (Fredrik Jonsson) wrote:
> Why shouldn't virtual members in a base class be forced by the compiler to be
                                                   ^^^^^^
> declared as virtuals when they are overloaded in a derived class? ...
...
> Is there a opinion out there about this?
>
> Fredrik Jonsson
> ELLEMTEL

IMHO this is not needed in general. Everything work fine as long you
are using these methods on objects. (I.e. no references, no pointers,
then static type == dynamic type). Virtual methods create an overhead.
The (successfull) C++ philosphy is not to produce overhead that is not
realy needed. So I am afraid that your suggestion woun't be accepted
as standard ISO-C++.
If a compiler forces you to do something (i.e. if you don't it's an ERROR)
that is not required by the standard this compiler is not standard-compliant.
But I learned in this thread every compiler is free to produce the
warnings it wants.

I agree that it is a good idea if the compiler issues a WARNING:
(a) when one tries to call a non-virtual method of a reference/pointer-object
when there exists a derived class where this method is redefined.
[ I know that the compiler compiling one translation-unit does not
know all classes that (will) 'exist' (in a programm), so this check
is incomplete. But in many cases it would help.]

(b) or additially to (a) when an object is passed by reference/pointer
as actual parameter of a function. Then there is the chance that
within this function (that might be in a translation-unit that does
not know that there is a derived class) a method is called that
was redefined in the derived class.
[ This check is more restrictive but I think it is complete. ]


Ulf Schuenemann

--------------------------------------------------------------------
Ulf Sch�nemann
Institut f�r Informatik, Technische Universit�t M�nchen.
email: schuenem@informatik.tu-muenchen.de




