Article View: gnu.g++.bug
Article #1791Re: virtual bugs/features
From: Dirk Grunwald
Date: Wed, 01 Mar 1989 16:10
Date: Wed, 01 Mar 1989 16:10
45 lines
2144 bytes
2144 bytes
In article <8902280000.AA02932@riunite.aca.mcc.com> rfg@MCC.COM (Ron Guilmette) writes:
(2) The compiler allows you to explicitly declare a destructor as being
virtual but you cannot explicitly declare a constructor as being virtual.
Is this intentional, or is thus a bug?
-- Declaring a destructor to be ``virtual'' means that if I have:
class A { ~A() };
class B : A { ~B() };
A *a; B *b;
b = new B; // all this is ``legal'' so far, if
a = b; // A & B were real classes
delete a;
If ~A() is not virtual, then the delete will call ~A().
If ~A() is virtual, then the delete will call ~B().
This only make sense because we can alias the subclass to the parent class.
You can't do this with constructors. See C++ manual.
(3) If you explicitly declare the destructor for a base
class as being virtual, then there will be a vtable built for that
.....
Feature. See above & C++ manual.
(4) Like the case with destructors, if I have a method
.....
things (a), (b), and (c) are bugs? Which ones are "features"?
All are features. See C++ manual about virtuals. It's not as straight-forward
as it seems. I think that it might be good to have a -W flag to point out
``hidden'' virtuals. This would be particularly useful for people
subclassing library routines. It would let you notice changes to the library
routines that might affect you code.
--
Dirk Grunwald
Univ. of Illinois
grunwald@flute.cs.uiuc.edu
Technical Details
Message-ID:
<GRUNWALD.89Mar1101003@flute.cs.uiuc.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!elroy!aero!venera.isi.edu!uci-ics!orion.cf.uci.edu!ucsd!nmtsun!unmvax!tut.cis.ohio-state.edu!rutgers!deimos.cis.ksu.edu!uxc!garcon!garcon.cso.uiuc.edu!grunwaldReferences:
<8902280000.AA02932@riunite.aca.mcc.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!elroy!aero!venera.isi.edu!uci-ics!orion.cf.uci.edu!ucsd!nmtsun!unmvax!tut.cis.ohio-state.edu!rutgers!deimos.cis.ksu.edu!uxc!garcon!garcon.cso.uiuc.edu!grunwald From: grunwald@flute.cs.uiuc.edu (Dirk Grunwald) Newsgroups: gnu.g++.bug Subject: Re: virtual bugs/features Message-ID: <GRUNWALD.89Mar1101003@flute.cs.uiuc.edu> Date: 1 Mar 89 16:10:04 GMT References: <8902280000.AA02932@riunite.aca.mcc.com> Sender: news@garcon.cso.uiuc.edu Distribution: gnu Organization: University of Illinois, Urbana-Champaign Lines: 45 In-reply-to: rfg@MCC.COM's message of 28 Feb 89 00:00:53 GMT