Basic definitions

< cpp‎ | language
Revision as of 08:05, 3 August 2013 by (Talk)

C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Function declaration
Lambda function declaration
inline specifier
Exception specifications (deprecated)
noexcept specifier (C++11)
decltype (C++11)
auto (C++11)
alignas (C++11)
Storage duration specifiers
Alternative representations
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Attributes (C++11)
typedef declaration
Type alias declaration (C++11)
Implicit conversions - Explicit conversions
static_cast - dynamic_cast
const_cast - reinterpret_cast
Memory allocation
Class-specific function properties
Special member functions

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



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)




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)

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 a
extern const int b = 1; // defines b

  • 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


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.


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.


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