Hello everyone,

I am trying to pre-allocate a certain number of nodes to a linked list, I allocate 10 nodes at first and, if I have more data to store, I'll need to resize it by adding half of the total number of nodes, sort of like 10, second time 5, and the third time is 15/2=7 nodes. It is giving me 2 errors C2664 on lines 154 and 163, where I'm trying to add nodes it is saying that I can't convert from const int to const staticList<T>::Node<T>. And also I'm trying to insert about a million of same same data elements.
Please Help :)

Thank you!

Recommended Answers

All 4 Replies

Why would you want to pre-allocate memory for a linked list? If you want to do that, you may aswell use a vector (or a deque).

The thing is that in my cpp file I'll be timing both the dynamic and the list with pre-allocated nodes. I think that the one with pre-allocation should be faster, but the downside will be when I'm trying to add the last few items and I pre-allocate a huge chunk of memory, which is going to be a waste :)

>> I think that the one with pre-allocation should be faste

First rookie mistake, pre-optimization!

Forget about it using pre-allocation. Just do it without it. It will definitely be fast
enough, unless you have some special case.

Well my first list that is without pre-allocation is done, the problem is with the other linked list that does pre-allocation. I need to do it because it's an assignment :) In my file here, I'm trying to make a function that creates arrays of nodes and then I pass it to my AddToRear function. But the thing is that it gives me an error when I try to do something like Head=new Node<T>(item); and again that's in the staticList class. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.