Dereferencing a pointer within a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry Lindsey

    Dereferencing a pointer within a function

    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::get Node(int which){
    ListNode *curNode;
    curNode=rootNod e;
    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


  • Larry Lindsey

    #2
    Re: Dereferencing a pointer within a function

    Nevermind, I figured it out. It turned out to be a dumb error.


    Comment

    Working...