dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Re: Destructors in Theme Editor: virtual or non virtual?

Re: Destructors in Theme Editor: virtual or non virtual?

From: Robert Bieber <>
Date: Thu, 17 Jun 2010 14:11:26 -0400

On 06/17/2010 04:27 AM, Al Le wrote:
> Hello.
> Out of curiosity I looked at the code of the Theme Editor which is written in C++. And saw, e.g. in the class SkinViewer, that the destructor is declared as a non-virtual function. But shouldn't (almost always) destructors be declared as virtual functions so that the framework (Qt in this case) can correctly destroy custom objects?
> Just digging out some long forgotten C++ rests out of my memory...

You are correct, I should be making them virtual (I'll go and fix that
shortly). Strictly speaking, it isn't an issue unless you declare
children of a class that has a non-virtual destructor. The compiler
will always ensure that all parent-class destructors are called in order
at destruction, but if you inherit from a class that has a non-virtual
destructor, and then you delete a pointer to the base class which is
also an instance of the child class, the child class' constructor won't
be called. Now that someone else has mentioned it, I do think that
having the original base class constructor virtual makes all the
following destructors virtual, but it's still safest to just explicitly
declare them all that way.

-Robert Bieber
Received on 2010-06-17

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy