第一次尝试调用 - > getValue()看起来不错,但只是下面的行(while循环的头)给我在getValue方法中的错误“访问冲突”。
if(first != 0){ listElement *that = first; cout << "add: " << that->getValue() << " | " << value << endl; while(that->getValue() < value) {..} }我可以在通话过程中编辑值吗? get方法只包含“返回值”....
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"....
最满意答案
明显的解释是在这段代码中
while(that->getValue() < value) {..}在{..}你正在做that = that->next; 并将其设置为空指针。
你需要在while循环中添加一个测试that != NULL ,以防止到达列表的末尾,而不会找到符合搜索条件的项目。
while(that != NULL && that->getValue() < value)如果您包含了所有代码,那将会有所帮助,因为似乎代码的关键位在{..}块中!
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!
更多推荐
发布评论