C++/C++ 문법 범범조조 2018. 5. 9. 14:00
자료형 bool C언어에서는 참과 거짓을 나타내기 위해서는 아래와 같이 #define (매크로 상수)을 이용하여 정의를 하여야 했다. #define TRUE 1 #define FALSE 0 하지만 C++ 에서는 자료형 bool 형식을 이용하여 true, false 를 표현할 수 있다. 위와 같이 C++에서는 bool이라는 자료형을 사용할 수 있다.
더 읽기
C++/MFC 범범조조 2018. 5. 4. 10:53
MFC를 이용하여 소켓 프로그래밍 작업 중 AfxGetMainWnd() 함수를 사용하던 중 뜻하지 않은 에러를 마주하게 되었습니다. 웹 검색을 통해서 알아본 결과 다른 함수와는 달리 AfxGetMainWnd() 함수는 스레드와 관련이 있어서 주의하여야 한다고 합니다. _AFXWIN_INLINE CWnd* AfxGetMainWnd() { CWinThread *pThread = AfxGetThread(); return pThread != NULL ? pThread -> GetMainWnd() : NULL; } 위의 코드를 보시게 되면 내부에서 AfxGetThread() 함수를 사용하는 것을 볼 수가 있습니다. 즉, 현재 스레드의 GetMainWnd() 함수를 호출합니다. 이와 같은 사용은 다른 스레드에서 메..
C++/C++ 문법 범범조조 2018. 5. 4. 08:00
인-라인 함수 - 기본적으로 C언어에서 매크로 함수라고 해서 지원하는 문법이 있습니다. 매크로 함수의 장점 – 실행 속도의 향상이 있습니다. 매크로 함수의 단점 – 구현이 어렵다는 단점이 있습니다. 아래는 매크로 함수의 예제입니다. C++에서의 인-라인 함수 사용법 - 컴파일러에 의해서 처리됩니다. - 구현의 용이성 제공을 합니다. - C언어에서의 매크로 함수의 장점을 그대로 반영했습니다. 아래는 C++ 에서의 인-라인 함수의 예제입니다.
C++/설명 범범조조 2016. 4. 20. 12:39
-상속과 다형성 최종 실습(학생 프로그램)//Student.h#pragma once#include #include using namespace std; class Student { string name; //학생 이름 const int number; //학생 주민번호 static int last_number; //학생 주민번호 순차 int hp; int iq; int stress; int scnt; static const int Def_Hp; static const int Max_Hp; static const int Min_Hp; static const int Def_Iq; static const int Max_Iq; static const int Min_Iq; static const int Def_St..
C++/설명 범범조조 2016. 4. 20. 12:36
-상속과 다형성 실습2(상품, 할인상품)시나리오1. 상품상품 이름과 가격을 멤버 필드로 갖습니다.생성할 때 이름과 가격을 입력 인자로 받습니다.가격과 이름의 접근자를 제공하며 가격 접근자는 가상 메서드 입니다.상품 정보를 출력하는 가상 메서드를 제공합니다.형식 내부에서만 접근 가능한 가격 설정자와 이름 절정자가 있습니다. 2. 할인상품할인율을 멤버 필드로 갖습니다.상품 이름과 가격, 할인율을 입력 인자로 받습니다.가격 접근자와 상품 정보 출력하는 메소드를 재정의 합니다.할인율의 접근자 메서드를 제공합니다.형식 내부에서만 접근할 수 있는 할인율 설정자가 있습니다. //DiscountProduct.h#pragma once#include "Product.h" class DiscountProduct :publi..
C++/설명 범범조조 2016. 4. 20. 12:33
-상속과 다형성 실습 1. 도형 //Diagram.h#pragma once#include #include using namespace std; class Diagram{ const int id; static int last_id;public: Diagram(); virtual void Draw() = 0;protected: int GetID()const;}; //Diagram.cpp#include "Diagram.h" Diagram::Diagram():id(last_id++){}void Diagram::Draw(){}int Diagram::GetID()const{ return id;} //Line.h#pragma once#include "Diagram.h"#include "POint.h" class Li..
C++/설명 범범조조 2016. 4. 19. 21:28
-파생 개체의 생성과 소멸 과정//상속 개요#include #include using namespace std; class Musician{ string name; //멤버 필드는 무조건 privatepublic: Musician(string name) { this->name = name; coutPlay(); pianist->View(); pianist->Turning(); delete pianist; return 0;}
C++/설명 범범조조 2016. 4. 19. 21:27
-추상 클래스#include #include using namespace std; class Musician{ string name;public: Musician(string name) { this->name = name; } virtual void Play() = 0; //순수 가상 메소드(추상 클래스)(기능 구현을위한 약속 메소드) void Introduce() { coutIntroduce(); musician->Play();} void StartConcert(Musician &musician){ musician.Introduce(); musician.Play();}
C++/설명 범범조조 2016. 4. 19. 21:26
-인터 페이스#include #include using namespace std; #define interface structinterface IPlay{ virtual void Play() = 0;}; //#define interface class //class를 이용하여 인터페이스를 만듬//interface IPlay//{//public:// virtual void Play() = 0;//} class Man:public IPlay{ string name;public: Man(string name) { this->name = name; } virtual void Play() { cout
-하향 캐스팅#include #include using namespace std; class Musician{ string name;public: Musician(string name) { this->name = name; } virtual void Play() = 0; //순수 가상 메소드(추상 클래스)(기능 구현을위한 약속 메소드) void Introduce() { coutIntroduce(); //실행 시간에 musician이 Pianist인지 확인하여 하향 캐스팅 //만약 피아니스트가 아니면 캐스팅 실패하고 0을 반환함 //Pianist *pianist = (*Pianist)musician; //CPP에서는 강제 형변환을 사용하지 마세요 Pianist *pianist = dynamic_cast(m..
C++/설명 범범조조 2016. 4. 19. 21:25
-무효화//무효화#include #include using namespace std; class Programmer{public: void Programming() { coutProgramming(2); Programmer *pro = ehp; pro->Programming(); pro->Programming(3); delete ehp; return 0;}
C++/설명 범범조조 2016. 4. 19. 21:24
-형식의 다형성#include #include using namespace std; class Musician{ string name;public: Musician(string name) { this->name = name; } void Play() { coutPlay();} void StartConcert(Musician &musician){ musician.Play();}