I was writing some utility routines for my game and I came upon a problem when I was testing one. I wrote a linked-list routine with pointers to the addition and comparison functions. Something like...
struct LLtNode{void* data;LLtNode* prev;LLtNode* next};
typedef void (*AddFn)(void*&,void*&);
typedef int (*CmpFn)(void*&,void*&);
class list{
protected:
LLtNode Head;
LLtNode cursor;
AddFn AddVal;
CmpFn Compare;
public:
//all the linked list methods you''d expect to find
};
You set AddVal and Compare when you create an instance of list. AddVal takes to pointers, and sets what value the first is pointing to, and sets that value to what the second is pointing to. The Compare function does just that, it compares the two values that its given. Usually a search value and the value a certain node holds, i.e. Compare(val,Cursor->data);. Well, I get an Access violation.
int Comp(void*& value,void*& source)
{//I''m testing it with int''s, and yes the add fuction uses ints
//too
int a,b;
a= *(int*)value;
b= *(int*)source;//access violation here
//goes on to compare the two values and returns the apropriate
//responce
};
Any Ideas why?
Remember that all the memory is allocated in the add funtion. And that in the add function I''m allowed to set the value of the Node, I just can''t access it. <style>a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};
Why is it called a hot water heater? Isn''t it cold when it goes in the tank?
-=CF=-</html>