c++ 질문있습니다 ㅠㅠㅠ 괴수님들 부탁드립니다
조회수 1901회
#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;
}
제가 지금 String 형식을 저장하는 singly linked list를 만들고 있는데요 ㅠㅠ StringLinkedList에서 public영역에 return head->elem;이부분과 addFront에서 v->elem=e; v->next=head; 마지막으로 removeFront()에서 head=old->next;부분에 오류가 뜨는데요. ㅠㅠ 부탁드리겠습니다. 고수님들 ㅠㅠ 오류내용은 캡쳐로 또 올리겠습니다 ㅠ 그리고 혹시 friend class를 사용해서 이런 오류가 뜨는건가요??? friend class가 무슨 의미인지 잘 모르겠습니다 ㅠ
오류내용은 아래와 같습니다 ㅠ 심각도 코드 설명 프로젝트 파일 줄 비표시 오류(Suppression) 상태 오류 C2248 'StringNode::elem': private 멤버('StringNode' 클래스에서 선언)에 액세스할 수 없습니다. Project12 c:\users\강명진\source\repos\project12\project12\main.cpp 21
댓글 입력