Я создаю функцию, которая удаляет головной узел связанного списка и делает его главой другого связанного списка. Я прототипировал функцию moveNode в внешнем классе под названием LinkedList, и позже я определил функцию в своем коде. Однако мой компилятор дает мне сообщения об ошибках, в которых говорится: «class LinkedList :: Node является приватным» и «LinkedList :: Node» LinkedList: голова закрыта. Я не понимаю, что мне нужно сделать, чтобы исправить это.У меня есть прототип функции, но мой класс все еще говорит, что это не член?
#include <iostream>
#include <cstdlib>
using namespace std;
class LinkedList
{
public:
LinkedList() { head = NULL; } // default constructor
friend ostream& operator<<(ostream& os, const LinkedList &ll);
void insertHead(int item); // insert at the head of the list
int count(int searchFor, const LinkedList &ll);
void moveNode(LinkedList &other, LinkedList ¤tList);
private:
class Node // inner class for a linked list node
{
public:
Node(int item, Node *n);
int data; // the data item in a node
Node *next; // a pointer to the next node in the list
};
Node *head; // the head of the list
};
LinkedList::Node::Node(int item, Node *n)
{
data = item;
next = n;
}
ostream& operator<<(ostream& os, const LinkedList &ll)
{
LinkedList::Node *current;
for(current = ll.head; current != NULL; current = current->next)
{
os << current->data << " ";
}
}
int LinkedList::count(int searchFor, const LinkedList &ll)
{
LinkedList::Node *current;
current = ll.head;
int howmanytimes = 0;
while(current != NULL){
if(current->data == searchFor)
{
howmanytimes++;
}
}
cout << searchFor << " appears in " << ll << " | " << howmanytimes << "time(s)" << endl;
}
void moveNode(LinkedList &other, LinkedList ¤tList)
{
LinkedList::Node *current = other.head;
if(current!=NULL)
{
current->next = currentList.head;
}
}
void LinkedList::insertHead(int item)
{
head = new Node(item, head);
}
'недействительным LinkedList :: moveNode (LinkedList & другие, LinkedList и CurrentList)' должны это исправить. –