[英]Call object type 'ListNode *' is not a function or function pointer
The line 8 in the first function: 第一个功能的第8行:
ListNode* prev = &dummy;
Have a error: Call object type 'ListNode *' is not a function or function pointer
The following is the code in .cpp : 以下是.cpp中的代码:
ListNode* deleteDuplicatesII(ListNode* head)
{
if (head == nullptr) return nullptr;
ListNode dummy(-1);
dummy.next = head;
ListNode* prev = &dummy; // Error here: Call object type 'ListNode *' is not a function or function pointer
for (ListNode* cur = prev->next(), *next = cur->next; next != nullptr;)
{
if (cur->value == next->value)
{
while (next != nullptr && cur->value == next->value)
{
cur->next = next->next;
delete next;
next = cur->next;
}
prev->next = cur->next;
delete cur;
cur = prev->next; // now the cur == next
if (cur == nullptr) break;
else next = cur->next; // maybe cur is nullptr
}
else
{
prev = cur;
cur = next;
next = next->next;
}
}
return dummy.next;
}
ListNode* Solution::reverseLinkedList(ListNode* head, int m, int n)
{
ListNode dummy(-1);
dummy.next = head;
head = &dummy; // It works well
for (int i = 0; i < m - 1; i++) {
head = head->next;
}
ListNode* prev = head->next;
ListNode* cur = prev->next;
for (int i = m; i < n; i++, cur = prev->next) {
prev->next = cur->next;
cur->next = head->next;
head->next = cur;
}
return dummy.next;
}
This is the code in .h 这是.h中的代码
struct ListNode
{
ListNode* next;
int value;
ListNode(int v): value(v), next(nullptr){}
};
The error only happened in the first function. 该错误仅在第一个函数中发生。 but works well in the second function.
但在第二个功能上效果很好。 And I have tried to change the local variable dummy and prev to another name.
而且我尝试将局部变量dummy和prev更改为另一个名称。 But it always report a error.
但是它总是报告一个错误。 I really don't know what causes the error.
我真的不知道是什么原因导致了错误。 Please provide details and I will appreciate it.
请提供详细信息,我将不胜感激。
在for循环中的next ..之后删除括号。.它是一个属性,但是使用括号,编译器认为它是方法/函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.