Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/language"

From cppreference.com
< cpp
(typo)
(Classes: +explicit)
Line 127: Line 127:
 
* {{rl|friend | friend specifier}} grants access privileges to private/protected parts for non-member classes or functions
 
* {{rl|friend | friend specifier}} grants access privileges to private/protected parts for non-member classes or functions
 
* {{rl|initializer_list | initializer lists}}
 
* {{rl|initializer_list | initializer lists}}
* {{rl|virtual | virtual functions}}
+
* {{rl|virtual | virtual function specifier}} declares a virtual functions
 +
* {{rl|explicit | explicit function specifier}} declares that a constructor or casting operator can not be used in implicit conversions
  
 
====Special member functions====
 
====Special member functions====

Revision as of 12:25, 31 January 2012

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

Contents

General topics

Preprocessor

Comments

Keywords

ASCII chart

Escape sequences

History of C++

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

  • for executes loop
  • range-for executes loop over a range (since C++11)
  • while executes loop, checking condition before each iteration
  • do-while executes loop, checking condition after each iteration

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

  • fundamental types defines basic character, integer and floating point types
  • compound types defines types, holding several data members (essentially the same as class)
  • enumeration types defines types, that are able to hold only one of the specified values
  • union types defines types, that can hold data in several representations
  • function types define function call signatures, that is the types of arguments and the return type
  • decltype specifier defines a type, equivalent to the type of an expression (since C++11)

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 (since C++11)
  • auto specifier specifies that the actual type shall be defined from the expression, assigned to the variable (since C++11)
  • alignas specifier specifies that the storage for the variable should be aligned by specific amount (since C++11)

Literals

Literals are the tokens of a C++ program that represent constant values, embedded in the source code.

Expressions

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 specified 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 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

Miscellaneous