Dereferencing a pointer within a function

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top