250x250
Notice
Recent Posts
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
관리 메뉴

일상 코딩

[C++/8.14] 클래스 안에 포함된 자료형 Nested types 본문

C++/따배C++ 08강 객체지향 기초

[C++/8.14] 클래스 안에 포함된 자료형 Nested types

polarcompass 2021. 10. 26. 21:01
728x90
#include <iostream>
using namespace std;

class Fruit
{
public:
    enum FruitType
    {
        APPLE,
        BANANA,
        CHERRY,
    };

    class InnerClass
    {
    };

    struct InnerStruct
    {
    };

private:
    FruitType m_type;

public:
    Fruit(FruitType type)
        : m_type(type)
    {
    }

    FruitType getType() { return m_type; }
};

int main()
{
    Fruit apple(Fruit::APPLE);

    if (apple.getType() == Fruit::APPLE)
    {
        cout << "Apple" << endl;
    }

    return 0;
}
728x90