🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1389

Re: Compiler should generate virtual destructors

#1389
From: John MAX Skaller
Date: Mon, 04 Jan 1993 15:48
49 lines
2606 bytes
In article <C0Ayt4.263@fiu.edu> feathers@serss0 (Michael Feathers) writes:
>In article <1992Dec31.050150.28929@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
>>I would like to propose that if a class has virtual functions,
>>then any destructor generated by the compiler will be virtual
>>by default.
>>
>>(The suggestion was first read by me in a paper of Markku Sakkinen,
>>who claims it was not his idea originally either.)
>>
>>Advantages: much safer, ensures correct deletion of objects
>>by default.  Removes a source of bugs. Removes the reminder
>>that its wise to do this from the FAQ.
>
>This would be a way in which a function within the source code would be
>virtual without the keyword 'virtual' having been used on it or a function of
>the same name in an inherited class.  That would bother me as a consistency 
>issue.

	Yes. But it is also a way to have a virtual function which
is NOT in the source code at all. Worse, it only applies
if the base class already has at least one virtual function.

>
>>Disadvantage: might slow down destruction a little. Can be
>>fixed by the programmer explicitly declaring a non-virtual
>>destructor.
>
>The only way to make something explicity non-virtual would be the absence
>of the 'virtual' keyword, unless we add a new keyword <shudder>.

	Yes, just define a destructor in the base class without
the keyword virtual.
>
>If the destructor is going to be made virtual by that rule, there is no
>need to declare it virtual.  But we can not make it explicitly non-virtual
>unless the virtual keyword is an option.

	Sure we can:

	class X { virtual fred(); } // has a virtual destructor
	class Y { virtual fred(); ~Y(){} }; // non-virtual destructor

The rule only applies to compiler generated destructors.

-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
Technical Details
Message-ID: <1993Jan4.154817.2032@ucc.su.OZ.AU>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
References: <1992Dec31.050150.28929@ucc.su.OZ.AU> <C0Ayt4.263@fiu.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: Compiler should generate virtual destructors
Message-ID: <1993Jan4.154817.2032@ucc.su.OZ.AU>
Sender: news@ucc.su.OZ.AU
Nntp-Posting-Host: extro.ucc.su.oz.au
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
References: <1992Dec31.050150.28929@ucc.su.OZ.AU> <C0Ayt4.263@fiu.edu>
Date: Mon, 4 Jan 1993 15:48:17 GMT
Lines: 49