[Digikam-devel] Re: Logic error
Marcel Wiesweg
marcel.wiesweg at gmx.de
Mon Nov 22 08:59:39 GMT 2010
> Basically since we inherit from QWidget most of the time, a virtual
> destructor should always be used, since QWidget provides virtual methods?
Yes, any QObject-derived class will already have a virtual destructor.
The simple rule is "make your destructor virtual if your class has any virtual
functions":
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.7
As far as I see GCC always gives a warning if you have virtual methods and not
virtual destructor in a base class
There is a small group of classes which will not need a virtual destructor: If
a class has a private QSharedDataPointer d-pointer, then it will usually not
be subclassed and not be created on the heap.
And fast "inline" classes, like DColor, shouldnt have this.
> Like I said I converted every destructor to be virtual in my branch and I
> can not see any slowdowns.
I would say there is the "slowdown" of the indirect call through the vtable,
which should be negligible in most cases. For memory cost, I think every
object will get an additional pointer.
The question is, which classes remain if you keep aside all QObject-derived
ones, which have it already, and all implictly/explicily-shared classes, which
dont need it?
Marcel
More information about the Digikam-devel
mailing list