🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Pure virtual destructors: good or bad idea?

#510
From: Stephen Clamage
Date: Fri, 14 Sep 1990 15:24
31 lines
1575 bytes
shankar@hpclscu.HP.COM (Shankar Unni) writes:

>PURE VIRTUAL DESTRUCTORS:

>One of our users came up with an interesting construct:

>   class Base {
>     virtual ~Base() = 0;	// pure virtual destructor
>   };

I really don't see what problem this user is trying to solve.  No class
is required to have a destructor, so if you don't want a destructor
called for class Base, don't define one.

Virtual destructors are a fine idea.  To enforce virtual destructors
in a hierarchy, put an empty virtual destructor in the most base class:
	class Base { ... virtual ~Base(){} ... };

If you wish to create an abstract class, pure virtual functions are a
big help.  Define the abstractions to be realized in derived classes
as pure virtual in the base class.  The destructor is not such a
candidate.

If a base class has a destructor, it must be called when a derived class
is destroyed; if the destructor is pure virtual it cannot be called.
Messing up the semantics of destructors to accomodate this idea would
have to be compensated by some real advantage.  I can't see that there
is any advantage in pure virtual destructors.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Technical Details
Message-ID: <455@taumet.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve
References: <77210003@hpclscu.HP.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve
From: steve@taumet.com (Stephen Clamage)
Newsgroups: comp.std.c++
Subject: Re: Pure virtual destructors: good or bad idea?
Message-ID: <455@taumet.com>
Date: 14 Sep 90 15:24:35 GMT
References: <77210003@hpclscu.HP.COM>
Organization: Taumetric Corporation, San Diego
Lines: 31