Original Post
Ok, This is beginning to get on my nerves. I have designed a simple Queue class (because the STL version was ALSO giveing me problems). Anyway, the problem is, that when I try to "delete" a node, i get an access violation. here is the source:
It isnt all that complicated, the problem occurs in the pop() function, the line "delete c;". The error, specifically, is
template <class t>
struct QNode
{
t data;
QNode* next;
QNode()
{
next = NULL;
}
};
template <class t>
class Queue
{
public:
Queue();
~Queue();
void push(t item);
t pop();
BOOL empty();
t peek();
private:
QNode<t>* first;
};
template <class t>
Queue<t>::Queue()
{
first = NULL;
}
template <class t>
Queue<t>::~Queue()
{
}
template <class t>
void Queue<t>::push(t item)
{
QNode<t>* c = first;
QNode<t>* d = first;
while(c)
{
d = c;
c = c->next;
}
c = new QNode<t>;
c->data = item;
if(d) d->next = c;
else first = c;
}
template <class t>
t Queue<t>::pop()
{
t tmp = first->data;
QNode<t>* c;
c = first;
first = first->next;
delete c;
return tmp;
}
template <class t>
BOOL Queue<t>::empty()
{
return (first == NULL);
}
template <class t>
t Queue<t>::peek()
{
return first->data;
}
|
HEAP[Divinity.exe]: Invalid Address specified to RtlValidateHeap( 9b0000, 8b1220 )copied from the debug output. I am assuming that new is giving me memory that starts before the heap does. Anyway, if anyone has ever had this problem before, this is a bit urgent (hint =), and if anyone knows how to fix it, I would be very grateful! Z.