QLinkedList size at declaration?
-
This might be a stupid question, but please don't shoot me down! I'm new to both C++ and Qt.
Can size be specified at declaration in case of LinkedLists?
@QLinkedList<int> list(10);@
This throws me the following error:
105: error: no matching function for call to 'QLinkedList<int>::QLinkedList(int)'But I've taken this line straight from the C++ GUI programming with Qt, SE.
-
QLinkedList does not support predefinition of size. It growth when new element is linked to it. As I saw in "documentation":http://qt-project.org/doc/qt-4.8/QLinkedList.html there is no possibility to pre allocate size.
But, if you need to reserve space for your list Qt offers "QList":http://qt-project.org/doc/qt-4.8/qlist.html and there is possibility to reserve space for elements "reserve":http://qt-project.org/doc/qt-4.8/qlist.html#reserve -
Thanks, that makes sense. I guess the book is wrong then.
-
It makes absolutely no sense for a linked list to pre-allocate elements because elements are not stored sequentially, not only is there nothing to gain from pre-allocation but it will mess up the implementation logic of the linked list.