[Qt-interest] QList<T> conversion

Konstantin Tokarev annulen at yandex.ru
Tue Feb 1 14:49:31 CET 2011



01.02.2011, 16:42, Oliver.Knoll at comit.ch:
> On 2011-02-01 Gustavo Gustavo de Sá Carvalho Honorato wrote:
>
>>>  ...
>>>     QList<A *> list;
>>>     QList<QObject *> objectList  *reinterpret_cast<QList<QObject
>>>  *>*>(&list);
>>>
>>>  The data structures in QList<T*> are isomorphic for all T.
>>  What you mean with isomorphic?
>
> Isomorphism is a very basic property of any OO-related language. It means that the list contains items of type T or derivatives thereof, or in other words: the list can contain *different* types (with the common base type T), and when you *assume* that *all* items are of type A (which inherit from T), well then, that just remains an assumption.
>
> This assumption might be valid in your specific case, but not in the general case, hence the disclaimer. Because your program would blow up the universe, if the list contained items of type A and B...

For example, it's possible to specialize implementation of QList<T> for A or B in such way that assumption will be broken

-- 
Regards,
Konstantin



More information about the Qt-interest-old mailing list