Basic definitions

From cppreference.com
 
 
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Initialization
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

This page provides definitions for the specific terminology used when describing the C++ programming language.

Contents

[edit] Identifier

An identifier is an arbitrarily long sequence of letters, digits, and underscores, that begins with a non-digit.

Identifiers can be freely used in a C++ program to name objects, types, and other entities, with the following exceptions:

  • The identifiers that are keywords cannot be used for other purposes.
  • All identifiers with a double underscore anywhere are reserved
  • All identifiers that begin with an underscore followed by an uppercase letter are reserved.
  • All identifiers that begin with an underscore are reserved for use at global namespace.

('reserved' means that standard library headers #define or declare such names for their internal needs, and if the programmer uses such names, a name collision may occur)

[edit] Entity

The entities of a C++ program are values, objects, references, functions, enumerators, types, class members, templates, template specializations, namespaces, parameter packs, and the this pointer.

[edit] Name

Names are identifiers used in a program, plus names of operator functions (operator+, operator bool, operator "" _km), and template ids (name<arg, arg>), if they are used to refer to entities.

The process by which the compiler decides whether a name encountered in a program names a type, a template, or some other entity is called name lookup. The text of a C++ program cannot be parsed if lookup cannot be performed (which sometimes requires explicit disambiguation)

[edit] Declarations and definitions

Declarations introduce (or re-introduce) names into the C++ program. Each kind of entity is declared differently. Definitions are declarations that are sufficient to use the entity identified by the name.

Only the following declarations are not definitions:

  • Function declaration without a function body

int f(int); // declares, but doesn't define f

  • Any declaration with an extern specifier or a linkage specifier (such as extern "C") without an initializer

extern const int a; // declares, but doesn't define c
extern const int b = 1; // defines c

  • Declaration of a static data member inside a class definition

struct S {    // defines S
    int n;        // defines S::n
    static int i; // declares, but doesn't define S::i
};
int S::i; // defines S::i

  • Declaration of a class name (forward declaration)

struct S; // declares, but doesn't define S

  • Opaque declaration of an enum.

enum Color : int; // declares, but doesn't define Color

  • Declaration of a template parameter

template<typename T> // declares, but doesn't define T

[edit] Type

Each object, reference, and function in C++ is associated with a type, which is defined at the point of declaration and cannot change. The type of an entity defines its possible values, possible operations, and their meaning. Types in C++ are nominal: two types may define exact same range of values and allowed operations, but if they are named differently, objects of those types are not compatible.

[edit] Object

An object is a region of storage, which has storage duration and a type (other than function, reference, or void type).

If an object is created by a definition, it has a name (objects created by new-expressions and temporary objects created while evaluating rvalue expressions have no names).

An object may contain subobjects (subobjects are either class member subobjects, base subobjects, or array elements).

Some objects are polymorphic: the types of such objects can be determined during program execution. For other objects, the type information is only available during compilation.

[edit] Variable

A variable is a named object or a named reference to an object. Const-qualified objects are also referred to "variables".

[edit] Scope