728x90

공부 중 메모/수업 예제 (KGCA) 29

Cpp 상속 예제

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. parents.h #pragma once #include using std::cout; using std::endl; class parents { private: int money; public: void Character(); //성품 출력 void Appearance(); //외모 출력 void Wealth(); //재산 출력 parents(); //생성자 parents(int money); //생성자 virtual ~parents(); //소멸자 }; parents.cpp #include "parents.h" void parents::Character() { cout

Cpp 복사 생성자 예제 (explicit, mutable)

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. explicit : 생성자 앞에 붙여서 묵시적 형변환을 금지하는 키워드mutable : 변수 앞에 붙여서 const함수에서도 값이 변경될 수 있도록 하는 키워드. classes.h #pragma once #include class class_A { private: int m_iValue; public: int Get() const { return m_iValue; } class_A(int iValue) : m_iValue(iValue) {} class_A(class_A& copy) : m_iValue(copy.m_iValue) {} ~class_A() { } }; class class_E { privat..

Cpp Friend 클래스 예제 (문자열 쪼개기)

header.h #pragma once #include #include #include #include #include #include #include #define SPA _T(" ") using std::vector; using std::string; using std::stringstream; using std::getline; using std::wcout; using std::endl; using std::cout; value.h #pragma once #include "value.h" //예외 클래스 인듯. class EXP { public: void show(TCHAR* pData) { wcout m_szValue = new TCHAR[iSize]; _tcscpy_s(m_szValue, iS..

Cpp 연산자 오버로딩 예제

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. pt.h #pragma once #include using namespace std; //const char& operator []() const; //char& operator [] (); //두 함수는 별개의 함수가 된다. ... const 함수냐 아니냐의 차이. class pt { static int dynamic; int x, y; public: void SetPosition(int _x, int _y); void Move(int _x, int _y); void Show(); //포인터 연산자 재정의 pt* operator->(); pt& operator* (); //증가 연산자 재정의 pt op..

Cpp 클래스 예제 (2) 사각형 충돌체크

Region.h #pragma once #include //const char* p = 0; //비상수 포인터, 상수 데이터 //char* const p = 0; //상수 포인터, 비상수 데이터 //const char* const p = 0; //상수 포인터, 상수 데이터 //void a() const { } // 상수 함수 : 함수에서 멤버 변수 값 변경 불가능 //const 함수에서는 const 함수만 호출 가능 //const int a() { }// 반환값이 상수, 상수 변수로만 반환 값을 받을 수 있음. class Region { public: enum { POINT_POINT, POINT_SIZE };//시작점과 끝점, 시작점과 길이 int m_iWidth; int m_iHeight; priva..

Cpp 클래스 기본

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. point.h #pragma once #include class Point { private: int x, y; public: void SetPosition(int _x, int _y); void Move(int _x, int _y); void Show(void); Point(); ~Point(); }; point.cpp #include "Point.h" void Point::SetPosition(int _x, int _y) { x = _x; y = _y; } void Point::Move(int _x, int _y) { x += _x; y += _y; } void Point::Show(void) { s..

Cpp 구조체 예제 (2) (비트필드 구조체)

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. #include using namespace std; struct PERSON { intage; longss; floatweight; charname[25]; } family_member; struct CELL {//비트필드 구조체 unsigned short character : 8;// 00000000 ???????? unsigned short foreground : 3;// 00000??? 00000000 unsigned short intensity : 1;// 0000?000 00000000 unsigned short background : 3;// 0???0000 00000000 unsigned ..

Cpp 구조체 예제(1)

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. #include using namespace std; #define cpp #ifdef C //C스타일 struct Point { int x, y; }; //전역 함수로 처리함 void SetPosition(Point *pPoint, int _x, int _y) { pPoint->x = _x; pPoint->y = _y; } void Move(Point *pPoint, int _x, int _y) { pPoint->x += _x; pPoint->y += _y; } void Show(const Point *pPoint) { printf("(%d,%d)\n", pPoint->x, pPoint->y); } i..

C언어 파일 입출력 예제

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. 1) #include int main() { intiValue = 50; floatfValue = 3.141592f; FILE*fp; fopen_s(&fp, "demo.txt", "w"); { fprintf(fp, "%s", "========= KGCA ========="); fprintf(fp, "\n%s", "홍길동"); fprintf(fp, " %d %f", iValue, fValue); } fclose(fp); iValue = 99; fValue = 6.26f; fopen_s(&fp, "demo.txt", "a"); { fprintf(fp, "\n%s ", "개통이"); fprintf(fp, "%..

C언어 공용체 예제

출처 : KGCA 게임 아카데미(http://www.kgcaschool.com/). 수업 예제 파일. #include union TData { char a; int b; double c; }; //비트필드 구조체 struct TBool { unsigned char a : 1; unsigned char b : 1; unsigned char c : 1; unsigned char d : 1; unsigned char e : 1; unsigned char f : 1; unsigned char g : 1; unsigned char h : 1; }; //비트필드구조체와 공용체 typedef struct { union { struct { unsigned long Zone : 28; unsigned long Level..

반응형