From: Gerhard Menzl on
Dave Steffen wrote:

> There's good reason to have a pure virtual dtor if the class needs to
> be abstract, but all the other member functions need to be "impure
> virtual" (e.g. virtual but not pure virtual) for some reason.
>
> Admittedly, I don't have any good examples of why such a design would
> be useful, but...

What about: GoF State Pattern, state base class has reasonable default
implementations for all virtual handler functions, hence the only way to
make the base class abstract is to provide it with a pure virtual
destructor.

--
Gerhard Menzl

Non-spammers may respond to my email address, which is composed of my
full name, separated by a dot, followed by at, followed by "fwz",
followed by a dot, followed by "aero".



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: peter koch larsen on
On 7 Mar., 01:57, Dave Steffen <dgstef...(a)numerica.us> wrote:
> "peter koch larsen" <peter.koch.lar...(a)gmail.com> writes:
>
> > On 6 Mar., 11:14, sk.sma...(a)gmail.com wrote:
> > > Hi,
>
> > > Can there be any use of "Pure Virtual Destructor"? If yes, then
> > > in what scenario do we use it?
>
> > You can, but I see no reason to have one - except perhaps for one
> > bizarre situation where the destructor is the main theme of the
> > class. Keeping it virtual and empty is sufficient.
>
> There's good reason to have a pure virtual dtor if the class needs to
> be abstract, but all the other member functions need to be "impure
> virtual" (e.g. virtual but not pure virtual) for some reason.
>
> Admittedly, I don't have any good examples of why such a design would
> be useful, but...
Exactly. It is legal, but not useful. If a class is abstract, it must
be because there's some functionality that needs to be filled in. It
is difficult to imagine, however, that this functionality should all
be in the destructor.

/Peter


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Dennis (Icarus) on
"Val" <valosmith(a)gmail.com> wrote in message
news:1173196295.237848.323320(a)s48g2000cws.googlegroups.com...
> { Quoted clc++m banner removed. -mod }
>
> This is talked about in detail in Item 14 of "Effective C++" by
> Meyers.
>
> You can't have a pure virtual destructor if the compiler is following
> the language spec. If you were to derive a concrete class from the
> abstract one, then create and destroy an object, the base class's
> destructor would be invoked immediately before the derived
> destructor. If the base destructor isn't implemented, then this is a
> problem.

I thought that destructors of derived classes were invoked before those of
base classes?


--
Dennis



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Gerhard Menzl on
peter koch larsen wrote:

> Exactly. It is legal, but not useful. If a class is abstract, it must
> be because there's some functionality that needs to be filled in. It
> is difficult to imagine, however, that this functionality should all
> be in the destructor.

I don't quite follow your logic here. Making a virtual destructor pure
doesn't mean that it contains all functionality. It indicates that all
other virtual functions have default implementations. Admittedly, not a
very frequent scenario, but not altogether outlandish either.

--
Gerhard Menzl

Non-spammers may respond to my email address, which is composed of my
full name, separated by a dot, followed by at, followed by "fwz",
followed by a dot, followed by "aero".



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: peter koch larsen on
On 8 Mar., 09:29, Gerhard Menzl <clcppm-pos...(a)this.is.invalid> wrote:
> peter koch larsen wrote:
> > Exactly. It is legal, but not useful. If a class is abstract, it must
> > be because there's some functionality that needs to be filled in. It
> > is difficult to imagine, however, that this functionality should all
> > be in the destructor.
>
> I don't quite follow your logic here. Making a virtual destructor pure
> doesn't mean that it contains all functionality. It indicates that all
> other virtual functions have default implementations. Admittedly, not a
> very frequent scenario, but not altogether outlandish either.

So if I understand you correctly, you use the virtual destructor as a
hint that other functions are virtual with a "questionable" default
implementation? This is silly. If anything, this behaviour requires an
implicit understanding which should be given in a better way than by
requiring the implementor to write an empty destructor.

/Peter


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]