Having a little trouble pushing a new entry onto a queue. (note this is a double-ended queue, so I can push/pop from either end).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main()
{
//instantiate a new queue
Deque<D_Node<size_t> > q;
//create a new D_Node to push onto the Deque
D_Node<int> first_node(1, NULL, NULL);
D_Node<int> *head_ptr;
D_Node<int> *tail_ptr;
head_ptr = &first_node;
tail_ptr = &first_node;
//push the D_Node onto the front of the Deque
q.push_front(first_node);
return 0;
}
The compiler is telling me that there is no matching function call, but I don't see why?
Perhaps it's because you're passing in a D_Node<int> rather than a D_Node<size_t>. You should change all the D_Node<int>s accordingly in main. This should make it compile fine.
You'll be out of luck for it running fine, however. This:
my_front = entry;
merely overwrites the front entry. That will only work if the queue is empty. If you keep calling push_front it will keep overwriting the front and thus it will not be adding anything to the queue. Instead, if the queue is not empty, you need to keep track of your (old) my_front, set my_front to the new entry, and set the new entry's next to the (old) my_front.
ahura24 wrote:
i think you dont define operator =
This will be a problem if your D_Node class uses dynamic memory.
Perhaps it's because you're passing in a D_Node<int> rather than a D_Node<size_t>. You should change all the D_Node<int>s accordingly in main. This should make it compile fine.
I noticed that, too, and changed everything to size_t before my last post. I should have mentioned that.
Thanks for the warning on my_front = entry. Since my_front is a pointer to the front entry, I was thinking that this would just change which entry my_front is pointing to, no?
So, now I have two questions:
1. How do handle the compilation error about cannot convert...
2. How to get the the my_front pointer to point to the correct entry. This one doesn't sound that tough.
It's question 1 that I need to solve first since the thing won't compile right now.