简体   繁体   English

调用对象类型“ ListNode *”不是函数或函数指针

[英]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.

相关问题 调用对象上的特定函数(函数指针) - Call a particular function (function pointer) on an object shared_ptr:“在没有适当的operator()或将函数转换为指针到函数的类型的情况下,调用类类型的对象” - shared_ptr : “call of an object of a class type without appropriate operator() or conversion function to pointer-to-function type” 称为 object 类型 'int' 不是 function 或 function 指针 - Called object type 'int' is not a function or function pointer 被调用的对象类型 bool 不是函数或函数指针 - called object type bool is not a function or function pointer 指向函数的指针是函数对象类型吗? - Is a pointer-to-function is a function object type? 调用对象'char *'类型不是函数或函数指针 - called object 'char* 'type is not a function or function pointer 称为“自动”的对象类型不是函数或函数指针 - Called object type 'auto' is not a function or function pointer 错误的 function 调用调用成员 function 指向 object 的指针 - Bad function call in calling member function pointer from pointer to an object c ++模板调用函数指针类型 - c++ template call of function pointer type 使用未知指针类型调用函数重载 - Call function overloads with unknown pointer type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM