🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Andrew Koenig Mon, 04 Jan 1993 03:40
virtual destructors by default
#1206
Author: 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
Re: virtual destructors by default
#1391
Author: Harvey Reed
Date: Mon, 04 Jan 1993 19:38
15 lines
843 bytes
ark@alice.att.com (Andrew Koenig) writes:

>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.

I agree. Tis better for compilers to make the programmer more aware,
than to do too much automatically.


-- 
++harvey
========================================================================
internet:  harvey@opl.com  /  hreed@cs.ulowell.edu  /  h.reed@ieee.org
voice:     617-965-0220
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads