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;
^~~~
之前我都是这么使用的,而且编译都过了 请大神解决一下我的困惑。

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

老哥解决了吗,我也遇到了同样的问题

private放到public前面,否则编译器不知道ListNode是个啥玩意