Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- dynamic
- 기초
- python
- W3Schools
- parameter
- c++
- DP
- 프로그래밍
- Class
- Tutorial
- Unreal Engine 5
- Programming
- guide
- loop
- w3school
- Algorithm
- Basic
- 백준
- 재귀
- Unity
- 문제풀이
- String
- UE5
- 파이썬
- Material
- C#
- github
- 오류
- dfs
- 시작해요 언리얼 2022
Archives
- Today
- Total
행복한 개구리
C++ Classes - Inheritance / Access Specifiers 본문

접근 지정자
당신은 접근 지정자 챕터에서 배웠듯이 C++에는 세 가지 접근 지정자가 존재합니다. 현재까지는 우리는 public 과 private 만 이용했습니다. 세 번재 지정자인 protected 는 private 과 비슷하지만 상속된 클래스에서는 접근할 수 있게 해줍니다:
예시
#include <iostream>
using namespace std;
// 기반 클래스
class Employee {
protected: // protected 접근 지정자
int salary;
};
// 파생 클래스
class Programmer : public Employee {
public:
int bonus;
void setSalary(int s) {
salary = s;
}
int getSalary() {
return salary;
}
};
int main() {
Programmer myObj;
myObj.setSalary(10000);
myObj.bonus = 15000;
cout << "Salary: " << myObj.getSalary() << "\n";
cout << "Bonus: " << myObj.bonus << "\n";
return 0;
}

'C++ > 공부내용' 카테고리의 다른 글
| C++ Classes - Files (0) | 2022.06.30 |
|---|---|
| C++ Classes - Polymorphism (0) | 2022.06.30 |
| C++ Classes - Inheritance / Multiple Inheritance (0) | 2022.06.29 |
| C++ Classes - Inheritance / Multilevel Inheritance (0) | 2022.06.29 |
| C++ Classes - Inheritance / Inheritance (0) | 2022.06.29 |