百度说是要加个判断检查返回值是否为NULL,可是这里只是定义了一个指针啊,没有用NEW申请内存,为什么还会有警告?
void Find_Middle(linklist Headnode) //链表的中间元素
{
linklist pFast, pSlow;
pFast = Headnode;
pSlow = Headnode;
while ((pFast != NULL) && (pFast->next != NULL))
{
pFast = pFast->next->next;
pSlow = pSlow->next;
}
if (Length_Node(Headnode) % 2 == 1)
cout << "Middle is " << pSlow->m << endl;
else
{
//----------**-以下两句都有警告-**---------------
cout << "Middle is " << pSlow->m << endl;
cout << "Middle is " << pSlow->next->m << endl;
}
return;
}
错误代码C28182 取消对 NULL 指针的引用。“pSlow”包含与“pFast”相同的 NULL 值。
错误代码C6011,取消NULL指针对pSlow->next的引用