Dereferencing a pointer within a function

Discussion in 'C++' started by Larry Lindsey, Sep 24, 2003.

  1. 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
     
    Larry Lindsey, Sep 24, 2003
    #1
    1. Advertising

  2. Nevermind, I figured it out. It turned out to be a dumb error.
     
    Larry Lindsey, Sep 24, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter L.
    Replies:
    3
    Views:
    379
    Jakob Bieling
    Feb 17, 2004
  2. BigMan
    Replies:
    51
    Views:
    7,237
    Rolf Magnus
    Feb 17, 2005
  3. Richard Cavell
    Replies:
    4
    Views:
    7,020
    Karl Heinz Buchegger
    Feb 16, 2005
  4. Vam
    Replies:
    1
    Views:
    381
    Victor Bazarov
    Feb 18, 2005
  5. viza

    dereferencing function pointer types

    viza, Jul 1, 2008, in forum: C Programming
    Replies:
    9
    Views:
    807
    Antoninus Twink
    Jul 2, 2008
Loading...

Share This Page