| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- html plug-in
- html object
- 하이퍼레저패브릭
- #android activity
- #C++ has~a
- html multimedia
- html code
- mac terminal command
- #CallByAddress
- hyperledger transaction
- #3차원배열
- #C++ 연산자함수오버로딩
- html charset
- border-box
- #자바상속#자바이즈어#is~a
- #bubbleSort
- #binary
- 토큰경제
- #JAVASCRIPT
- #2차원배열
- #1차원배열
- html id
- html youtube
- html video
- docker example
- #다차원포인터
- #성적관리프로그램
- html5 new tag
- relative path
- git flow
Archives
- Today
- Total
A sentimental robot
Friend 본문
friend
단점: 캡슐화가 파괴될 위험이 있다.
장점: 코드의 확장
1. class
2. member function 잘 안쓰임
3. function 제일 잘 쓰인다.
function
|
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 |
#include<iostream>
using namespace std;
class A
{
int a;
public:
friend void disp();
};
void disp()
{
A aa;
aa.a = 100; // A클래스에서 friend로 선언했기 때문에 A의 private int a에 접근가능 ; 캡슐화 파괴
cout << aa.a << endl;
}
void main() {
disp();
} |
cs |
friend class
#include<iostream>using namespace std;class A{friend class B; // B를 친구로 등록int a; // B에서 A클래스의 private 접근 가능};class B{A aa;public:void dispA(){aa.a = 10;cout << aa.a << endl;}};void main() {B bb;bb.dispA();}
'C++ ' 카테고리의 다른 글
| 대입연산자 (0) | 2018.09.19 |
|---|---|
| Operator function (1) | 2018.09.19 |
| Has~a exercise (0) | 2018.09.18 |
| Has~A (0) | 2018.09.18 |
| const (0) | 2018.09.17 |