C++ 접근 지정자 (Access Specifier)

2021. 3. 12. 17:47·C++/Class

접근 지정자 (Access Specifier)

  • 종류

    • public : 어디서든 접근 가능하다.

    • private : 해당 클래스와 friend 클래스만 접근 가능하다.

    • protected : private 특성을 기본으로, 상속받은 자식 클래스도 접근 가능하다.

  • 명시하지 않는 경우, 기본 값은 private이다.

  • private이어도 같은 클래스면 다른 인스턴스의 멤버를 사용할 수 있다.

    class Date
    {
      int    year_;
      int    month_;
      int    day_;
    
      void copyFrom(const Date& original)
      {
        year_ = original.year_;
        month_ = original.month_;
        day_ = original.day_;
      }
    };
  • public 멤버 변수들에 대해 uniform initialization이 가능하다.

    #include <iostream>
    
    class Date
    {
    public:
        int    year_;
        int    month_;
        int    day_;
    };
    
    int        main()
    {
        using namespace std;
    
        Date a{ 2021, 3, 1 };
        cout << a.year_ << ' ' << a.month_ << ' ' << a.day_ << '\n';
    }
    
    /* stdout stderr
    2021 3 1
    */
저작자표시 (새창열림)

'C++ > Class' 카테고리의 다른 글

C++ 복사 생성자(Copy Constructor)  (0) 2021.03.12
C++ 위임 생성자 (Delegating Constructor)  (0) 2021.03.12
C++ 멤버 초기화 리스트 (Member Initializer Lists)  (0) 2021.03.12
C++ 생성자 (Constructor)  (0) 2021.03.12
C++ Class  (0) 2021.03.12
'C++/Class' 카테고리의 다른 글
  • C++ 위임 생성자 (Delegating Constructor)
  • C++ 멤버 초기화 리스트 (Member Initializer Lists)
  • C++ 생성자 (Constructor)
  • C++ Class
Caniro
Caniro
  • Caniro
    Minimalism
    Caniro
  • 전체
    오늘
    어제
    • 분류 전체보기 (317)
      • Algorithm (13)
        • 알기 쉬운 알고리즘 (10)
        • Search (1)
        • Sort (2)
      • Arduino (0)
      • C++ (185)
        • Class (46)
        • Exception (6)
        • Library (51)
        • Overloading (10)
        • SmartPointer (5)
        • Syntax (33)
        • TBC++ (23)
        • Templates (9)
        • VisualStudio (2)
      • Embedded (1)
      • Git (4)
      • Java (5)
      • Linux (16)
        • Error (1)
        • Linux Structure (11)
      • MacOS (7)
      • OS (1)
        • Concurrency (1)
      • Python (21)
        • Class (1)
        • Function (2)
        • Syntax (17)
      • Raspberrypi (9)
      • Review (1)
      • Utility (12)
        • VSCode (5)
        • VirtualBox (3)
      • Web (8)
        • Nginx (1)
        • React (3)
        • Django (1)
      • Windows (20)
        • Registry (3)
        • WSL (1)
        • DeviceDriver (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    MacOS
    spring
    윈도우
    윈도우 명령어
    mspaint
    dism
    알림
    그림판
    로지텍 마우스 제스처
    citrix workspace
    SunOS 5.1
    windows
    스프링 프레임워크 핵심 기술
    시스템 복구
    Windows 11
    맥북 카카오톡 알림 안뜸
    EXCLUDE
    백기선
    SFC
    제외
    vscode
    스프링
    Workspace
    java
    logi options
    KakaoTalk
    Solaris 10
    unix
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
Caniro
C++ 접근 지정자 (Access Specifier)
상단으로

티스토리툴바