C++ language
From Cppreference
This is a brief reference of available C++ constructs.
Contents |
[edit] General topics
[edit] Preprocessor
[edit] Comments
[edit] Keywords
[edit] ASCII chart
[edit] Escape sequences
[edit] Flow control
[edit] Conditional execution statements
Different code paths are executed according to the value of given expression
[edit] Iteration statements
The same code is executed several times
- for executes loop
- range-for executes loop over a range (C++11 feature)
- while executes loop, checking condition before each iteration
- do-while executes loop, checking condition after each iteration
[edit] 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
[edit] Functions
The same code can be reused at different locations in the program
- declaring functions
- exception specifications enforces the function to throw only specific exceptions or not to throw at all (deprecated)
- noexcept specifier enforces the function not to throw any exceptions (C++11 feature)
- inline specifier hints the compiler to insert a function's body directly into the calling code
[edit] Exceptions
Exceptions are a more robust way to signal error condition than function return codes or global error variables
- throw expression signals an error and transfers control to error handler
- try-catch block catches exceptions originating from specific block of code
[edit] Namespaces
Namespaces provide a way to prevent name clashes in large projects
[edit] Types
- fundamental types define basic character, integer and floating point types
- compound types define types, holding several members of (potentially) different types
- function types define types, holding a pointer to a function
- decltype specifier defines a type, equivalent to the type of an expression (C++11 feature)
[edit] Specifiers
- cv specifiers specifies constness and volatility of a type
- storage duration specifiers specifies storage duration of a type
- constexpr specifier specifies that the value of a variable or function can be computed at compile time (C++11 feature)
- auto specifier specifies that the actual type shall be defined from the expression, assigned to the variable (C++11 feature)
[edit] 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 = rvalue |
++a --a |
+a -a |
!a a && b |
a == b a != b |
a[b] *a |
a(...) a, b |
Special operators | ||||||
static_cast converts one type to another compatible type |
- operator precedence the order in which operators are evaluated
- alternative representations alternative spellings for some of the operators
[edit] Utilities
- Types
- typedef declaration creates a synonym for a type
- type alias declaration creates a synonym for a type
- attributes defines additional information about variable (C++11 feature)
- Casts
- standard conversions implicit conversions from one type to another
- const_cast conversion
- static_cast conversion
- dynamic_cast conversion
- reinterpret_cast conversion
- Memory allocation
- new expression allocates memory dynamically
- delete expression deallocates memory dynamically
[edit] Classes
Classes provide the concept of object-oriented programming in C++
- declaring a class
- access specifiers
- friend specifier grants access privileges to private/protected parts for non-member classes or functions
- initializer lists
[edit] Special member functions
- default constructor initializes the object with default contents
- copy constructor initializes the object with the contents of another object
- move constructor initializes the object with the contents of other, temporary object, minimizing copying overhead (C++11 feature)
- 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 (C++11 feature)
- destructor releases claimed resources
[edit] Templates
Allows functions and classes to operate on generic types