일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- stencil buffer
- node.js
- react
- Expo
- unity stencil buffer
- react native 타입스크립트
- 리액트 네이티브 맥
- react-native
- 스탠실 버퍼 사용
- C++
- 스탠실 버퍼 시작
- react native typescript navigate
- 리액트 네이티브 설치 오류
- html
- react native
- CSS
- c++ 정보은닉
- node
- react native mac
- react native ios 기기 연결
- react native typescript
- 스탠실 버퍼 튜토리얼
- cyworld
- react native typescript navigation
- 벡터와 리스트의 차이
- 싸이월드
- c++ using
- react native accessible
- javascript
- GitHub
Archives
- Today
- Total
혀니의 이거저거 뿌시기
[C++]04-2.캡슐화(Encapsulation) 본문
728x90
#include <iostream>
using namespace std;
class SinivelCap
{
public:
void Take() const {cout << "콧물이 싹~ 납니다."<< endl;}
};
class SneezeCap
{
public:
void Take() const {cout << "재채기가 멎습니다."<< endl;}
};
class SnuffleCap
{
public:
void Take() const {cout << "코가 뻥~ 뚫립니다."<< endl;}
};
class CONTAC600
{
private:
SinivelCap sin;
SneezeCap sne;
SnuffleCap snu;
public:
void Take() const
{
sin.Take();
sne.Take();
snu.Take();
}
};
class ColdPatient
{
public:
void TakeCONTAC600(const CONTAC600 &cap) const {cap.Take();}
};
int main(void)
{
CONTAC600 cap;
ColdPatient sufferer;
sufferer.TakeCONTAC600(cap);
return 0;
}
코감기약 하나로 콧물, 재채기, 코 뚫림을 동시에 하게 하는 것
캡슐화의 범위를 정하는 일은 쉬운 일이 아님.
안에 있는 내용이 보이면 안되므로 기본적으로 정보은닉을 포함하는 개념이라고도 함..
윤성우 C++ p.166 정답
#include <iostream>
using namespace std;
class Point
{
private:
int xpos, ypos;
public:
void Init(int x, int y)
{
xpos = x;
ypos = y;
}
void ShowPointInfo() const
{
cout << "[" << xpos << "," << ypos << "]" << endl;
}
};
class Circle
{
private:
int rad;
Point point;
public:
void Init(int x, int y, int r)
{
rad = r;
point.Init(x,y);
}
void ShowCircleInfo() const
{
cout <<"radius: " <<rad <<endl;
point.ShowPointInfo();
}
};
class Ring
{
private:
Circle c1;
Circle c2;
public:
void Init(int x1, int y1, int r1, int x2, int y2, int r2)
{
c1.Init(x1, y1, r1);
c2.Init(x2, y2, r2);
}
void ShowRingInfo() const
{
cout << "Inner Circle Info..." << endl;
c1.ShowCircleInfo();
cout << "Outer Circle Info..." << endl;
c2.ShowCircleInfo();
}
};
int main(void)
{
Ring ring;
ring.Init(1,1,4,2,2,9);
ring.ShowRingInfo();
return 0;
}
728x90
'LANG > C++' 카테고리의 다른 글
[C++]04-4.클래스와 배열 그리고 포인터 (0) | 2023.05.12 |
---|---|
[C++] 04-3.생성자(Constructor)와 소멸자(Destructor) (0) | 2023.05.12 |
[C++]04-1.정보은닉(Information Hiding) (2) | 2023.05.12 |
[C++]03-3.객체지향 프로그래밍의 이해 (0) | 2023.05.12 |
[C++]03-2.클래스(Class)와 객체(Object) (0) | 2023.05.12 |