Reputation: 177
the first try to call that->getValue() looks good, but just the line below (the head of while loop) give me the error "access violation" inside the getValue method.
if(first != 0){
listElement *that = first;
cout << "add: " << that->getValue() << " | " << value << endl;
while(that->getValue() < value) {..}
}
Do i edit the the value during the call anywhere? The get method consists just of "return value"....
Upvotes: 0
Views: 157
Reputation: 613272
The obvious explanation is that in this code
while(that->getValue() < value) {..}
inside the {..}
you are doing that = that->next;
and setting that
to the null pointer.
You need to add a test for that != NULL
in your while
loop to protect against getting to the end of the list without finding an item that meets your search criterion.
while(that != NULL && that->getValue() < value)
It would have helped if you had included all the code because it seems that the key bit of code is in the {..}
block!
Upvotes: 4