close
Variants

C++ 언어

From cppreference.com
 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 

C++ 언어 구조의 간단한 참조 입니다.

일반 주제

전처리기(Preprocessor)

주석(Comments)

키워드(Keywords)

ASCII 문자표

특수문자

C++의 역사

기본 정의

흐름 제어

조건문

조건문은 주어진 표현식 값에 따라 서로 다른 코드 경로를 실행합니다.

  • if문은 조건부 코드를 실행합니다
  • switch문은 인자값에 따라 코드를 실행합니다

반복문

반복문은 코드 경로를 여러번 실행합니다.

  • for문은 초기문,비교문,그리고 증감문 지정에 의한 반복을 실행합니다
  • range-for문은 지정된 범위(range)에서의 반복문을 실행합니다(since C++11)
  • while문은 항상 반복 전에 조건을 확인 후 반복을 실행합니다
  • do-while문은 항상 반복 후에 조건을 확인하는 반복을 실행합니다

분기문

분기문은 다른 지역에서 프로그램 실행을 계속합니다

  • continue문은 반복문이 포함하는 코드 영역의 나머지 부분을 건너뜁니다.
  • break문은 반복문이 포함하는 코드 영역을 탈출합니다.
  • goto문은 또다른 지점에서 코드의 실행을 지속합니다.
  • return문은 함수가 포함하는 코드 영역의 실행을 종료합니다.

함수

동일한 코드의 경우 프로그램의 서로 다른 지점에서 재사용될 수 있습니다.

예외

오류 상태를 알리는데 있어 예외는 함수의 반환(return codes)이나 전역 변수(global error variables)보다 더 확실하고 강력한 수단입니다.

네임스페이스

네임스페이스는 대형 프로젝트에서 하나의 이름 충돌 방지 기법으로 사용됩니다.

타입

  • 기본타입들은 기본적인 문자, 정수, 부동 소수점 타입들을 정의합니다.
  • 포인터 타입은 메모리 장소를 가지고 있는 타입을 정의합니다.
  • 복합 타입은 여러가지 데이터 멤버를 가지는 타입을 정의합니다.(본질적으로 클래스와 동일함)
  • 열거형 타입은 하나의 지정된 값만 가질 수 있는 타입을 정의합니다.
  • 공용체 타입은 여러가지로 묘사될 수 있는 데이터를 가지는 타입을 정의합니다.
  • 함수 타입은 인자 타입들과 반환 타입으로된 함수의 호출 형태를 정의합니다.
  • decltype 지정자는 표현식의 타입과 동일한 타입을 정의합니다.(since C++11)

지정자

  • cv 지정자 타입들의 상수성(constness)과 최적화 금지(volatility)를 지정합니다.
  • storage duration 지정자는 타입들의 지속성(storage duration)을 지정합니다.
  • constexpr 지정자는 변수 또는 함수의 값이 컴파일 시간에 계산될 수 있음을 지정합니다.(since C++11)
  • auto 지정자는 변수에 할당된 표현식으로 부터 실제 타입이 정의됨을 지정합니다.(since C++11)
  • alignas 지정자는 변수가 정해진 크기에 따라 정렬되어 저장되야함을 지정합니다.(since C++11)

초기화

명명된 변수가 선언되거나 임시 객체가 생성되었을 때, 새로운 객체의 초기값은 다음과 같은 방식을 통해 제공됩니다:

리터럴(Literal)

리터럴은 소스코드에 이식된 상수값을 표현하는 C++ 프로그램의 토큰(token, 컴파일러의 워드 해석의 식별 단위) 이다.

표현식

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

a = b a += b a -= b a *= b a /= b a %= b a &= b a |= b a ^= b a <<= b a >>= b

++a --a a++ a--

+a -a a + b a - b a * b a / b a % b ~a a & b a | b a ^ b a << b a >> b

!a a && b a || b

a == b a != b a < b a > b a <= b a >= b a <=> b

a[...] *a &a a->b a.b a->*b a.*b

function call

a(...)
comma

a, b
conditional

a ? b : c
Special operators

static_cast converts one type to another related type
dynamic_cast converts within inheritance hierarchies
const_cast adds or removes cv-qualifiers
reinterpret_cast converts type to unrelated type
C-style cast converts one type to another by a mix of static_cast, const_cast, and reinterpret_cast
new creates objects with dynamic storage duration
delete destructs objects previously created by the new expression and releases obtained memory area
sizeof queries the size of a type
sizeof... queries the size of a pack (since C++11)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception (since C++11)
alignof queries alignment requirements of a type (since C++11)

유틸리티

Types
Casts
메모리 할당
  • new expression
    은 메모리를 동적으로 할당한다
    Original:
    allocates memory dynamically
    The 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 dynamically
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

클래스

클래스는 C++의 객체 지향 프로그래밍 컨셉을 제공한다.
Original:
Classes provide the concept of object-oriented programming in C++.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

클래스 지정 함수 속성

특수 멤버 함수

  • 기본 생성자는 객체를 기본값으로 초기화 합니다.
  • 복사 생성자는 객체를 다른 객체의 값으로 초기화 합니다.
  • 이동 생성자(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)
  • 소멸자 소유한 자원을 해제합니다.

템플릿

함수와 클래스들이 일반적인 타입들에 대해 동작하도록 해준다.

시작과 종료

  • a main function
    은 프로그램의 지정된 시작점을 제공한다
    Original:
    provides a designated starting point for the program
    The 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 shutdown
    The 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++ code
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.