#include <iostream>
#include <string>
using namespace std;
class StringNode {
private:
string elem;
StringNode* next;
friend class StringLinkedList;
};
class StringLikedList {
public:
StringLikedList() :head(NULL) {};
~StringLikedList() {
while (!empty())removeFront();
};
bool empty()const { return head == NULL; };
const string& front()const {
return head->elem;
};
void addFront(const string& e) {
StringNode* v = new StringNode;
v->elem = e;
v->next = head;
head = v;
};
void removeFront() {
StringNode* old = head;
head = old->next;
delete head;
};
private:
StringNode* head;
};
int main()
{
system("pause");
return 0;
}
I'm making a single linked list that stores the String format. ㅠ St In StringLinkedList, an error appears in the public area in return head->elem;this part and addFront in v->elem=e;v->next=head;and finally removeFront. Please. Masters. I'll upload the error information as a screenshot again 그리고 And is this error coming up using friend class?? I don't know what friend class means <
The contents of the error are as follows "T" Severity Code Description Project File Line Display Error (Suppression) Status Error C2248 'StringNode::lem': Unable to access private member (declared in class 'StringNode'). Project12 c:\users\Kang Myungjin\source\repos\project12\project12\main.cpp21
Members declared private in class StringNode cannot be accessed from the outside. If you specify a friend class, you can access it exceptionally, but there is a typo, so there is an error.
friend class StringLinkedList;
class StringLikedList
I think you omitted n from linked when you declared class.
© 2024 OneMinuteCode. All rights reserved.