Share via


C++ Primary Expressions

Primary expressions are the building blocks of more complex expressions. They are literals, names, and names qualified by the scope-resolution operator (::).

Syntax

  • primary-expression :
    literal
    this
    :: identifier
    :: operator-function-name
    :: qualified-name
    ( expression )
    name

A literal is a constant primary expression. Its type depends on the form of its specification. See Literals for complete information about specifying literals.

The this keyword is a pointer to a class object. It is available within nonstatic member functions and points to the instance of the class for which the function was invoked. The this keyword cannot be used outside the body of a class-member function.

The type of the this pointer is type *const (where type is the class name) within functions not specifically modifying the this pointer. The following example shows member function declarations and the types of this:

class Example
{
public:
    void Func();          //  * const this
    void Func() const;    //  const * const this
    void Func() volatile; //  volatile * const this
};

See Type of this Pointer for more information about modifying the type of the this pointer.

The scope-resolution operator (::) followed by an identifier, operator-function-name, or qualified-name constitutes a primary expression. The type of this expression is determined by the declaration of the identifier, operator-function-name, or name. It is an l-value if the declaring name is an l-value. The scope-resolution operator allows a global name to be referred to, even if that name is hidden in the current scope. See Scope for an example of how to use the scope-resolution operator.

An expression enclosed in parentheses is a primary expression whose type and value are identical to those of the unparenthesized expression. It is an l-value if the unparenthesized expression is an l-value.