|
Boost : |
From: Ralf W. Grosse-Kunstleve (rwgk_at_[hidden])
Date: 2008-05-03 10:22:54
Thanks for the explanation!
How about this?
Index: counted_base.hpp
===================================================================
--- counted_base.hpp (revision 45067)
+++ counted_base.hpp (working copy)
@@ -34,6 +34,10 @@
protected:
+// avoid warning: has virtual functions but non-virtual destructor
+#if defined(__GNUC__)
+ virtual
+#endif
~counted_base() throw()
{
}
Index: cloning_base.hpp
===================================================================
--- cloning_base.hpp (revision 45067)
+++ cloning_base.hpp (working copy)
@@ -23,6 +23,10 @@
protected:
+// avoid warning: has virtual functions but non-virtual destructor
+#if defined(__GNUC__)
+ virtual
+#endif
~cloning_base() throw()
{
}
----- Original Message ----
From: Peter Dimov <pdimov_at_[hidden]>
To: boost_at_[hidden]
Sent: Saturday, May 3, 2008 7:08:06 AM
Subject: Re: [boost] throw_exception rev. 44954 -> g++ warnings
Ralf W. Grosse-Kunstleve:
> My primary question still is:
> What is the disadvantage of adding the virtual destructors?
> The Stroustrup book has a very clear recommendation (below).
> Why not follow this advice? I'm keen to learn the facts.
A destructor that is never supposed to be called (except by the destructor
of the derived class) doesn't need to be virtual. There's not much point in
trying to avoid the undefined behavior in "delete sp.get()". sp is now a
time bomb.
A protected destructor, on the other hand, yields a compile-time error. You
can still make it virtual if you like. It's a bit contradictory for the
reader as you appear unable to make up your mind as to whether the
destructor is supposed to be part of the base class interface or not, but
most of them are familiar with g++ by now, so they won't be confused for
long.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk