Namespaces
Variants
Views
Actions

C++ language

From cppreference.com
< cpp
Revision as of 12:46, 7 November 2011 by P12 (Talk | contribs)

Template:cpp/language/sidebar This is a brief reference of available C++ constructs.

Contents

General topics

Preprocessor

Comments

Keywords

ASCII chart

Escape sequences

Flow control

Conditional execution statements

Different code paths are executed according to the value of given expression

  • if executes code conditionally
  • switch executes code according to the value of an integral argument

Iteration statements

The same code is executed several times

Jump statements

Continue execution at a different location

  • continue skips the remaining part of the enclosing loop body
  • break terminates the enclosing loop
  • goto continues execution in another location
  • return terminates execution of the enclosing function

Functions

The same code can be reused at different locations in the program

Exceptions

Exceptions are a more robust way to signal error condition than function return codes or global error variables

Namespaces

Namespaces provide a way to prevent name clashes in large projects

Types

Specifiers

Operators

  • operators allows 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 parameter 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)

Utilities

Types
Casts
Memory allocation

Classes

Classes provide the concept of object-oriented programming in C++

Special member functions

Templates

Allows functions and classes to operate on generic types