L
Larry Lindsey
I have a linked list class that is giving me problems when I try to return
the nth node. Here is what it looks like:
class LinkedList{
public:
ListNode getNode(int which);
int getValue();
....
private:
ListNode *rootNode;
};
class ListNode{
public:
int getValue();
ListNode* getNext();
ListNode* getPrev();
......
};
ListNode LinkedList::getNode(int which){
ListNode *curNode;
curNode=rootNode;
int k=0;
float testVal;
while(k<index){
k++;
curNode=curNode->getNext(); //this doesn't break anything
}
testVal=curNode->getValue(); //neither does this
cout<<testVal<<endl;
return *curNode; //as soon as i do this, i get an access
violation exception
}
I can access curNode's methods, but I can't actually dereference the
pointer. Does anyone know why this would be? Thanks
--Larry
the nth node. Here is what it looks like:
class LinkedList{
public:
ListNode getNode(int which);
int getValue();
....
private:
ListNode *rootNode;
};
class ListNode{
public:
int getValue();
ListNode* getNext();
ListNode* getPrev();
......
};
ListNode LinkedList::getNode(int which){
ListNode *curNode;
curNode=rootNode;
int k=0;
float testVal;
while(k<index){
k++;
curNode=curNode->getNext(); //this doesn't break anything
}
testVal=curNode->getValue(); //neither does this
cout<<testVal<<endl;
return *curNode; //as soon as i do this, i get an access
violation exception
}
I can access curNode's methods, but I can't actually dereference the
pointer. Does anyone know why this would be? Thanks
--Larry