Technote87 [C++] 캡슐화의 기본 개념 캠슐화 : 관련 있는 데이터와함수를 하나의 단위로 묶는 것 관련 있는 데이터와 함수를 클래스 라는 하나의 캡슐내에 모두 정의 하는것 #include using std::cout; using std::cin; using std::endl; class Point { int x; int y; public: int GetX(){return x;} int GetY(){return y;} void SetX(int _x); void SetY(int _y); }; void Point::SetX(int _x) { if(_x100) { cout 2009. 9. 20. [C++] 정보은닉 멤버 함수의 정의를 클래스 외부로 빼낼때, 클래스 내에 존재하는 멤버 함수의 선언에는 매개 변수의 타입과 개수에 대한 정보만 가지고 있어도 된다. void SetX(int); void SetY(int); #include using std::cout; using std::cin; using std::endl; class Point { int x; int y; public: int GetX(){return x;} int GetY(){return y;} void SetX(int _x); void SetY(int _y); }; void Point::SetX(int _x) { if(_x100) { cout 2009. 9. 20. [C++] 정보 은닉의 적용 #include using std::cout; using std::endl; using std::cin; class Point { int x; int y; public: int GetX(){return x;} int GetY(){return y;} void SetX(int _x){x=_x;} void SetY(int _y){y=_y;} }; int main() { int x,y; cout > x>>y; Point p; p.SetX(x); p.SetY(y); cout 2009. 9. 20. [C++] 정보은닉(Information Hiding)의 필요성 #include using std::cout; using std::endl; using std::cin; class Point { public: int x; int y; }; int main() { int x,y; cout > x >> y; Point p; p.x = x; p.y = y; cout 2009. 9. 19. 이전 1 2 3 4 5 ··· 22 다음