c++ 질문있습니다 ㅠㅠㅠ 괴수님들 부탁드립니다

조회수 1877회
#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

이미지

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    class StringNode 의 private으로 선언된 멤버는 외부에서 접근이 불가능합니다. friend class를 지정하면 예외적으로 접근이 가능하지만 오타가 있어서 오류가 발생하고 있네요.

    friend class StringLinkedList;
    class StringLikedList 
    

    class 선언하실 때 linked 에서 n 을 빼먹으신 것 같습니다.

    • (•́ ✖ •̀)
      알 수 없는 사용자
    • 와 역시 진심으로 감사합니다 ㅠㅠ 꾸벅 강명진 2019.1.6 01:16

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)