🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

virtual destructors by default

#1206
From: Andrew Koenig
Date: Mon, 04 Jan 1993 03:40
34 lines
1612 bytes
There are two problems with extending C++ so that
classes with virtual functions also automatically acquire virtual destructors:

1. It will be a long, long time before a careful programmer can take
   advantage of the feature, because if a program that does so is
   run under an implementation that doesn't support it, it will
   quietly do the wrong thing and the user will blame the author.

   In general, extensions that define previously undefined behavior
   (rather than defining previously illegal behavior) must be viewed
   with caution.

2. The proposal doesn't solve the whole problem: it is possible to write
   class definitions that have no virtual functions and nevertheless
   require a virtual destructor.  For instance:

   struct Thing { Thing(); ~Thing(); };
   struct B { };
   struct D: B { Thing t; };

   main()
   {
	B* bp = new D;
	delete bp;	// Oops!
   }

   The commented line is undefined unless D has a virtual destructor.

For these reasons, I am dubious about the proposal.  I do think, though,
that it is wise for compilers to issue warning messages for classes
with virtual functions that do not also have virtual destructors.
-- 
				--Andrew Koenig
				  ark@europa.att.com
Technical Details
Message-ID: <24544@alice.att.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark
From: ark@alice.att.com (Andrew Koenig)
Newsgroups: comp.std.c++
Subject: virtual destructors by default
Message-ID: <24544@alice.att.com>
Date: 4 Jan 93 03:40:43 GMT
Article-I.D.: alice.24544
Organization: AT&T Bell Laboratories, Murray Hill NJ
Lines: 34