调用对象类型 'ListNode *' 不是函数或函数指针
Call object type 'ListNode *' is not a function or function pointer
第一个函数中的第 8 行:
ListNode* prev = &dummy;
Have a error: Call object type 'ListNode *' is not a function or function pointer
以下是.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;
}
这是 .h 中的代码
struct ListNode
{
ListNode* next;
int value;
ListNode(int v): value(v), next(nullptr){}
};
错误仅发生在第一个函数中。 但在第二个函数中运行良好。我尝试将局部变量虚拟人和 prev 更改为另一个名称。但它总是报告错误。我真的不知道是什么原因导致错误。请提供详细信息,我将不胜感激。
next 之后删除括号。在 for 循环中..它是一个属性,但用括号,编译器认为它是一个方法/函数
相关文章:
- QMetaObject invokeMethod的基于函数指针的语法
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- c++r值引用应用于函数指针
- 模板函数指针和lambda
- 是否可以将llvm::FunctionType转换为C/C++原始函数指针
- 带有类的函数指针
- () 函子后面的括号,而不是函数指针?
- 全局作用域中函数指针的赋值
- 使用"Task"函数指针队列定义作业管理器
- 将成员函数指针作为参数传递给模板方法
- 如何创建对象函数指针C++映射?
- 匹配函数指针作为模板参数?
- 通过函数指针定义类范围之外的方法
- 存储在类中的函数指针
- C++从函数指针数组调用函数
- 将返回值存储在函数指针数组的指针中是如何工作的?
- 整数键映射到头文件中的成员函数指针
- 从类成员函数到类 C 函数指针的转换
- 如何将内联匿名函数分配给C++函数指针
- 将字符缓冲区强制转换为函数指针