강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

khb4435님의 프로필 이미지
khb4435

작성한 질문수

홍정모의 따라하며 배우는 C++

8.14 클래스 안에 포함된 자료형 nested types

강의랑 똑같은 입력

작성

·

201

0

#include <iostream>

using namespace std;

class fruit{

public:

    enum class fruitType{ //enum class

        apple,banana,cherry,

    };

private:

    fruitType m_type;

public:

    fruit(fruitType type):m_type(type){}

    

    fruitType getType(){ //fruitType형을 반환한다

        return m_type;

    }

};

int main(int argc, const char * argv[]) {

    fruit::fruitType Apple(fruit::fruitType::apple);

    if(Apple.getType() == fruit::fruitType::apple){

        cout<<"Apple!"<<endl;

    }

    return 0;

}

main문의 Apple.getType()에서 fruit::fruitType is not a structure or union이라는 오류메시지가 뜹니다 ㅠ memb  

ㄴㅁㅇㄹer reference base type 'fruit::fruitType' is not a structure or unioㅁㄴㅇㄹ

답변 1

0

안녕하세요

강의에선 fruit Apple(fruit::fruitType::apple); 라고 작성하였습니다..! 이렇게 작성하면 오류가 사라질 것입니다. 

질문글 작성 전에 강의와 똑같은 코드로 한게 맞는지 점검 부탁드립니다..! 감사합니다. 😊

khb4435님의 프로필 이미지
khb4435

작성한 질문수

질문하기