C++ 언어
C++ 언어 구조의 간단한 참조 입니다.
일반 주제
전처리기(Preprocessor)
주석(Comments)
키워드(Keywords)
ASCII 문자표
특수문자
C++의 역사
기본 정의
흐름 제어
조건문
조건문은 주어진 표현식 값에 따라 서로 다른 코드 경로를 실행합니다.
반복문
반복문은 코드 경로를 여러번 실행합니다.
- for문은 초기문,비교문,그리고 증감문 지정에 의한 반복을 실행합니다
- range-for문은 지정된 범위(range)에서의 반복문을 실행합니다(since C++11)
- while문은 항상 반복 전에 조건을 확인 후 반복을 실행합니다
- do-while문은 항상 반복 후에 조건을 확인하는 반복을 실행합니다
분기문
분기문은 다른 지역에서 프로그램 실행을 계속합니다
- continue문은 반복문이 포함하는 코드 영역의 나머지 부분을 건너뜁니다.
- break문은 반복문이 포함하는 코드 영역을 탈출합니다.
- goto문은 또다른 지점에서 코드의 실행을 지속합니다.
- return문은 함수가 포함하는 코드 영역의 실행을 종료합니다.
함수
동일한 코드의 경우 프로그램의 서로 다른 지점에서 재사용될 수 있습니다.
- 함수 선언문은 함수를 선언합니다
- 람다 함수 선언문은 람다 함수를 선언합니다 (since C++11)
- 함수 템플릿은 함수 템플릿를 선언합니다
- inline 지정자는 컴파일러가 함수 몸체를 직접 함수 호출 코드에 삽입하라는 힌트입니다
- 예외 명세서는 함수가 지정된 예외만을 던지도록 선언합니다 (deprecated)
- noexcept 지정자는 함수가 어떤 예외든 던질지의 여부를 선언합니다 (since C++11)
예외
오류 상태를 알리는데 있어 예외는 함수의 반환(return codes)이나 전역 변수(global error variables)보다 더 확실하고 강력한 수단입니다.
- throw 표현식은 오류를 알리고 제어권을 오류 처리기(error handlers)로 전달합니다.
- try-catch 블럭은 코드의 특정 블럭으로 부터 예외의 발생을 잡아냅니다
- noexcept 지정자와 noexcept 연산자는 표현식이 예외를 던지는지에 대하여 정의하고 테스트합니다
네임스페이스
네임스페이스는 대형 프로젝트에서 하나의 이름 충돌 방지 기법으로 사용됩니다.
- namespace declarations는 네임스페이스를 선언합니다.
- namespace aliases는 기존에 존재하는 네임스페이스의 대체 이름을 선언합니다.
타입
- 기본타입들은 기본적인 문자, 정수, 부동 소수점 타입들을 정의합니다.
- 포인터 타입은 메모리 장소를 가지고 있는 타입을 정의합니다.
- 복합 타입은 여러가지 데이터 멤버를 가지는 타입을 정의합니다.(본질적으로 클래스와 동일함)
- 열거형 타입은 하나의 지정된 값만 가질 수 있는 타입을 정의합니다.
- 공용체 타입은 여러가지로 묘사될 수 있는 데이터를 가지는 타입을 정의합니다.
- 함수 타입은 인자 타입들과 반환 타입으로된 함수의 호출 형태를 정의합니다.
- decltype 지정자는 표현식의 타입과 동일한 타입을 정의합니다.(since C++11)
지정자
- cv 지정자 타입들의 상수성(constness)과 최적화 금지(volatility)를 지정합니다.
- storage duration 지정자는 타입들의 지속성(storage duration)을 지정합니다.
- constexpr 지정자는 변수 또는 함수의 값이 컴파일 시간에 계산될 수 있음을 지정합니다.(since C++11)
- auto 지정자는 변수에 할당된 표현식으로 부터 실제 타입이 정의됨을 지정합니다.(since C++11)
- alignas 지정자는 변수가 정해진 크기에 따라 정렬되어 저장되야함을 지정합니다.(since C++11)
초기화
명명된 변수가 선언되거나 임시 객체가 생성되었을 때, 새로운 객체의 초기값은 다음과 같은 방식을 통해 제공됩니다:
- 기본 초기화(default initialization) 아무런 초기화 방식도 제공되지 않는 것.
- 값 초기화(value initialization) 비어있는 괄호 형태의 초기화 방식.
- 0 초기화(zero initialization) 객체의 모든 비트를 0 으로 초기화.
- 복사 초기화(copy initialization) 객체를 다른 객체로 부터 초기화.
- 직접 초기화(direct initialization) 괄호 사이에 초기값이나 생성자의 인자 리스트를 제공해주는 방식.
- aggregate initialization 배열이나 생성자가 없는 구조체의 모든 멤버들에 대해 초기 값을 제공해주는 방식.
- list initialization provides an arbitrary long list of values, which can initialize a
std::vectororstd::map(since C++11) - constant initialization initializes all constant static objects before anything else
- reference initialization binds references to objects and extend the lifetimes of the temporaries
리터럴(Literal)
리터럴은 소스코드에 이식된 상수값을 표현하는 C++ 프로그램의 토큰(token, 컴파일러의 워드 해석의 식별 단위) 이다.
- 정수형 리터럴(integer literals) are decimal, octal, or hexadecimal numbers of integer type.
- 문자 리터럴(character literals) are individual characters of type
char,char16_t,char32_t, orwchar_t - 소수점형 리터럴(floating-point literals) are values of type
float,double, orlong double - 문자열 리터럴(string literals) are sequences of characters, which may be narrow, multibyte, or wide
- 불린형 리터럴(boolean literals) are values of type
bool, that istrueandfalse - 널포인터(nullptr) is the pointer literal which specifies a null pointer value (since C++11)
- 사용자 정의 리터럴(user-defined literals) are constant values of user-specified type (since C++11)
표현식
An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects.
- value categories (lvalue, rvalue, glvalue, prvalue, xvalue) classify expressions by their values
- order of evaluation of arguments and subexpressions specify the order in which intermediate results are obtained
- operators allow the use of syntax commonly found in mathematics
| Common operators | ||||||
|---|---|---|---|---|---|---|
| assignment | increment decrement |
arithmetic | logical | comparison | member access |
other |
|
|
|
|
|
|
|
function calla(...)
|
commaa, b
| ||||||
conditionala ? b : c
| ||||||
| Special operators | ||||||
|
static_cast converts one type to another related type | ||||||
- operator precedence defines the order in which operators are bound to their arguments
- alternative representations are alternative spellings for some operators
유틸리티
- Types
- typedef declarations create synonyms for types
- type alias declarations create synonyms for types
- attributes define additional information about variables (since C++11)
- Casts
- standard conversions implicit conversions from one type to another
-
const_castconversion -
static_castconversion -
dynamic_castconversion -
reinterpret_castconversion - explicit cast conversion using C-style cast notation and functional notation
- 메모리 할당
- new expression은 메모리를 동적으로 할당한다Original:allocates memory dynamicallyThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - delete expression은 메모리를 동적으로 해제한다Original:deallocates memory dynamicallyThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
클래스
You can help to correct and verify the translation. Click here for instructions.
- class declarations는 클래스를 선언한다Original:declare classesThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
thispointer links to the current instance of a class in member methods - access specifiers determine visibility of class members
- friend specifier grants access privileges to private/protected parts for non-member classes or functions
- initializer lists initialize class member data
클래스 지정 함수 속성
- 가상함수 지정자(virtual function specifier) 는 함수가 가상임을 선언합니다
- override 지정자는 가상함수를 오버라이드한 또 다른 가상 함수임을 선언합니다. (since C++11)
- final 지정자는 상속한 클래스에서 가상 함수를 오버라이드 할 수 없음을 선언합니다. (since C++11)
- 명시적 함수 지정자(explicit function specifier) 는 생성자 또는 변환 연산자가 묵시적(implicit)으로 변환되는데 사용될 수 없음을 선언합니다. (since C++11)
- 정적 함수 지정자(static function specifier)는 함수가 클래스 데이터를 사용할 수 없음을 선언합니다.
- cv 함수 지정자(cv function specifier)는 멤버 함수가 오직 cv(상수나 최적화금지)한정된 객체에게 사용 되어짐을 선언합니다.
특수 멤버 함수
- 기본 생성자는 객체를 기본값으로 초기화 합니다.
- 복사 생성자는 객체를 다른 객체의 값으로 초기화 합니다.
- 이동 생성자(move constructor)는 객체를 다른 객체, 임시객체, 복사 오버헤드 최소화된 값 초기화 합니다.(with the contents of other, temporary object, minimizing copying overhead) (since C++11)
- assignment operator replaces the contents of the object with the contents of another object
- move assignment operator replaces the contents of the object with the contents of other, temporary object, minimizing copying overhead (since C++11)
- 소멸자 소유한 자원을 해제합니다.
템플릿
함수와 클래스들이 일반적인 타입들에 대해 동작하도록 해준다.
- 클래스 템플릿 선언 클래스 템플릿을 선언한다.
- 함수 템플릿 선언 함수 템플릿을 선언한다.
- 템플릿 특수화 기존 템플릿의 특정 타입에 대한 부분을 정의한다.
- 의존성 명칭들(dependent names) 인스턴스화 되는 시점에서 템플릿의 동작(behavior)이 바뀐다.
- 파라미터 꾸러미(parameter packs) 템플릿 내에서 타입 리스트를 사용할 수 있도록 허용한다. (since C++11)
시작과 종료
- a main function은 프로그램의 지정된 시작점을 제공한다Original:provides a designated starting point for the programThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - non-local variable initialization describes how static and thread-local variables (since C++11) are initialized
- termination은 프로그램 종료의 처리를 설명한다Original:describes the process of program shutdownThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
최적화
- the as-if rule allows any code transformation that doesn't change the output
- copy elision, including RVO and NRVO, makes pass-by-value the preferred approach in many situations.
- empty base optimization makes multiple inheritance from interfaces or policy classes overhead-free and is required for standard-layout types.
그외
- Inline assembly는 C++ 코드와 함께 어셈블리 코드의 사용을 가능하게 해준다Original:allows the use of assembly code alongside C++ codeThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.