James Kanze
12/12/2008 9:41:00 AM
On Dec 12, 1:05 am, joec...@gmail.com wrote:
> On Dec 11, 6:42 pm, "DavidW" <n...@email.provided> wrote:
> > I just to confirm a rule.
> > class B
> > {
> > public:
> > virtual ~B() {}
> > virtual void f();
> > };
> > class D : public B
> > {
> > public:
> > void f();
> > };
> > The virtual ~B() is necessary because B has at least one
> > virtual function, but an explicit d'tor is not required in
> > derived classes. Correct?
> Yes. You are correct. You will have a lot of people respond
> with a lot of detail about when you really need, and when you
> really don't need a virtual destructor, but "virtual
> destructor required when there are any virtual functions" is a
> good simple rule to live by.
Actually, the usual rule is that the base class destructor must
be either virtual or protected. And of course, it is a
"programming standards" rule, not something imposed by the
standard.
The standard actually violates it in several cases. Arguably,
it shouldn't, and the classes in question should have empty
protected destructors. Except that that would impose
restrictions on classes deriving from them, since no class
deriving from them would have a trivial destructor.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34