无法访问同一 class 中的私有成员

cannot access private member in the same class

我试图用私有结构声明一个 public 成员函数,但没有成功。有人可以帮我弄这个吗?这是头文件

class LinkedList
{
public:
   LinkedList();
   ~LinkedList();
   ...
   //I tried to add LinkedList also not working
   //void deleteNode(const LinkedList::Node* n);
   void deleteNode(const Node* n);

private:
    struct Node
    {
        std::string value;
        Node *next;
    };
class LinkedList
{
public:
   LinkedList();
   ~LinkedList();

   void deleteNode(const Node* n);

private:
    struct Node
    {
        std::string value;
        Node *next;
    };
};

Node是在void deleteNode(const Node* n);之后声明的,所以编译器不知道Node是什么。

你应该这样做:

class LinkedList
{
private:
    struct Node
    {
        std::string value;
        Node *next;
    };

public:
   LinkedList();
   ~LinkedList();

   void deleteNode(const Node* n);

};