Why does QQueue inherit from QList but QStack inherits from QVector? Is there any special reason? I mean, why can't it be the other way around or both QQueue and QStack inherit from one of QList or QVector?
Thanks.
Why does QQueue inherit from QList but QStack inherits from QVector? Is there any special reason? I mean, why can't it be the other way around or both QQueue and QStack inherit from one of QList or QVector?
Thanks.
Because QQueue prepends items whereas QStack appends them. QVector performs worse than QList when it comes to prepending, hence the inheritance choice for QQueue. As for QStack, it would be possible to make it inherit from QList AFAIK but the Trolls probably know what they are doing and there's at list a single reason that motivate their choice : as QVector pre-allocates memory only at its end (contrary to QList) their is no wastage (remember : QStack never prepend on its own, though the coder can do it manually...)
Hope this helps.![]()
Current Qt projects : QCodeEdit, RotiDeCode
There is no reason to inherit QStack from QList, because it would waste resources (QList has some extra space ready for incoming data at the beginning of its data structure).
Bookmarks