Namespaces
Variants
Views
Actions

Identifiers

From cppreference.com
< cpp‎ | language
Revision as of 11:23, 30 March 2013 by Cubbi (Talk | contribs)

 
 
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
 

An identifier is an arbitrarily long sequence of letters, digits, and underscores, which begins a non-digit. Identifiers are case-sensitive.

In declarations

Identifiers can be used to name objects, types, namespaces, 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)

In expressions

An identifier that names a variable or a function can be used as an expressions. The expression consisting of just the identifier returns the entity named by the identifier and its value category is lvalue if the identifier names a function, a variable, or a data member, and it is prvalue otherwise (e.g. the identifier nullptr is a prvalue expression)

Within the body of a non-static member function, each identifier that names a non-static member is implicitly transformed to a class member access expression.

Besides simple names of objects and functions, the following language constructs can be used in expressions in the same role (together with identifiers they are known as id-expressions)

  • name of an operator function, such as operator + or operator new
  • name of a user-defined conversion function, such as operator bool
  • name of a user-defined literal operator, such as operator "" _km
  • the character ~ followed by class name, such as ~MyClass
  • the character ~ followed by decltype specifier, such as ~decltype(str)
  • a template identifier, such as MyTemplate<int>
  • qualified identifiers, such as std::string or ::tolower

Qualified identifiers

A qualified identifier is an identifier, operator function name, literal operator name, or a template identifier that is prepended by a scope resolution operator ::, and optionally, a sequence of class or namespace names separated by scope resolution operators:

For example, the expression std::string::npos is an id-expression that names the static member npos in the class string in namespace std. The expression ::tolower names the function tolower in the global namespace. The expression ::std::cout names the global variable cout in namespace std, which is a top-level namespace. The qualified identifier boost::signals2::connection names the type connection declared in namespace signals2, which is declared in namespace boost.

The keyword template may appear in qualified identifiers as necessary to disambiguate dependent template names.