0
点赞
收藏
分享

微信扫一扫

runtime error: member access within null pointer of type ‘MyLinkedList::ListNode‘ (solution.cpp)

月半小夜曲_ 2022-04-15 阅读 52
c++

ERROR情况:

Line 40: Char 12: runtime error: member access within null pointer of type 'MyLinkedList::ListNode' (solution.cpp)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:45:12

问题原因:

运行时错误:“MyLinkedList::ListNode”(solution.cpp)类型的空指针内的成员访问
摘要:未定义的行为程序:未定义行为 程序_加入.cpp:45:12

就是没有考虑空指针的情况

解决方法:

// 需要考虑多种情况 
if(head==NULL)  return; 
if(p->next==NULL)  return;
一般判断语句中{ }(p->next && p->next->next)都存在
举报

相关推荐

0 条评论