It won't hurt to try

[C++/윈도우프로그래밍응용]19. 상속과 접근지정자 본문

C++/윈도우프로그래밍응용

[C++/윈도우프로그래밍응용]19. 상속과 접근지정자

yongki.doki 2021. 10. 24. 17:47
class ChildClass : <상속 접근 지정자> ParentClass {
  ...
}

예를 들어

protected ParentClass 가 있다고 하자

ChildClass에서 public으로 상속 접근 지정을 했다.

이러한 경우, protected로 상속한다.

반대로 ChildClass에서 private으로 상속 접근 지정을 했다.

이러한 경우, private로 상속한다.

 

※private으로 선언된 부모클래스의 속성은 상속할 수 없다.

 

class A {
  // 상속 접근 가능
  public:
    int a;
  // 상속 접근 가능
  protected:
    int b;
  // 상속 접근 불가능
  private:
    int c;
}
class B : private A {

}
300x250
300x250
Comments