[Development] QList

Marc Mutz marc.mutz at kdab.com
Sat Mar 25 08:57:57 CET 2017


On 2017-03-24 20:55, Thiago Macieira wrote:
> Em sexta-feira, 24 de março de 2017, às 09:18:05 PDT, Marc Mutz 
> escreveu:
>> > Are you of the opinion that private inheritance has no purpose and should
>> > never be used?
>> 
>> No, and if you look at code I have written over the years, you will 
>> see that
>> I do use it.
>> 
>> One thing I've looked into in the past is this: Q6Polygon should 
>> inherit a
>> Q6VectorBase<QPoint> that also Q6Vector<QPoint> inherits. This will 
>> allow
>> easy specialisation of QVector<T*> by inheriting QBasicVector<const 
>> void*>.
> 
> Can you elaborate on your thinking? What's QBasicVector and what's 
> QVector?

QBasicVector (or QVectorBase, or ...) is QVector with protection against 
using it as-is (e.g. protected dtor). QVector inherits QBasicVector to 
lift the restriction. This inheritance may even be public to avoid lots 
of using QBasicVector::foo; This is ok, because QBasicVector is not 
usable as-is, but I'd still make it private, because when you start to 
inherit to specialise (QVector<T*> : QBasicVector<const void*>), you 
don't want the void* methods to leak.

So, if you absolutely are set on inheritance, then use the same pattern. 
But I don't see this here. None of the points that makes this a good 
idea for QVector (or QVLA) pertains to QString: we don't need to fight 
template bloat, we don't have multiple classes inheriting QStringView...

Thanks,
Marc



More information about the Development mailing list