본문 바로가기

헤더파일

C++ 객체지향 프로그래밍 Chapter 22 상속과 포함 - 2 상속 문서 저장 클래스.의 구현. 예제에 쓰이는 각 코드들. DocWriter.h #ifndef DOCWRITER_H #define DOCWRITER_H #include using namespace std;// 스트링 클래스를 사용하기 위한 준비. class DocWriter { public: DocWriter(); DocWriter(const string& fileName, const string& content); ~DocWriter(); // 파일 이름을 지정 void SetFileName(const string& fileName); // 저장할 텍스트를 지정 void SetContent(const string& content); // 파일에 텍스트를 저장시킨다. void Write(); prote.. 더보기
C++ 객체지향 프로그래밍 Chapter 22 상속과 포함 상속과 포함 이래놓고 포함부터 가르치는 이유는 모르겠다.[제목과 순서의 미스매치.] ----------------------------- Rect::Rect(int left, int top, int right, int bottom) : _topLeft( left, top), _bottomRight( right, bottom) //초기화 리스트, {// ㄴ _topLeft 객체의 생성자를 호출한다. ㄴ _bottomRight 객체의 생성자를 호출한다. // 생성자의 코드 } -------------- 초기화 리스트로 객체의 생성자를 지정하는 코드 생성자의 실행 순서와 소멸자의 실행 순서는 다음과 같다 생성자의 경우 1. 밖의 생성자에서 쓰이는 속에있는 함수들이 먼저 실행된다. 2. 후에 밖의 생성자에서 쓰.. 더보기
C++ 객체지향 프로그래밍 Chapter 21 클래스와 객체 - 2 헤더 파일을 사용한 클래스의 예제. 각 파일별 코드가 있다. 일단은 main.cpp[메인이지만 이름은 아무렇게나 해도 상관없음.] #include "point.h" int main() { // 객체를 생성한다. Point pt; pt.SetX(50); pt.SetY(50); // pt의 내용을 출력한다. pt.Print(); return 0; } point.cpp #include "point.h" #include using namespace std; Point::Point(const Point& pt) { x = pt.x; y = pt.y; } Point::Point(int initialX, int initialY) { SetX(initialX); SetY(initialY); } Point::Point(.. 더보기