一周三更 2020-02-11 23:15 采纳率: 0%
浏览 1863

cannot convert 'ListNode*' to 'Solution::ListNode*' in initialization

我在leetcode上面刷一个比较简单的题目,但是出现了这样的问题让我一直解决不了。

#define MAX 100
class Solution {
public:
    bool hasCycle(ListNode *head) {
        int tag[MAX] = {0},i=0;
        ListNode* top = head;
        if(head == NULL) return false;
        else{
            while(top &&tag[i++] == 0)top = top->next;
            if(top == nullptr)
                return false;
            else
                return true;
        }
    }
private:
    struct ListNode{
        int val;
        ListNode *next;
        ListNode(int x) : val(x),next(NULL) {}
    };

};

错误显示 :
solution.cpp: In member function hasCycle
Line 15: Char 25: error: cannot convert 'ListNode*' to 'Solution::ListNode*' in initialization
ListNode* top = head;
^~~~
之前我都是这么使用的,而且编译都过了 请大神解决一下我的困惑。

  • 写回答

3条回答 默认 最新

  • threenewbee 2020-02-12 12:27
    关注

    为什么要把
    struct ListNode{
    int val;
    ListNode *next;
    ListNode(int x) : val(x),next(NULL) {}
    写在Solution 类定义里面,很奇怪

    评论

报告相同问题?