共用方式為


Postfix Expressions

Postfix expressions consist of primary expressions or expressions in which postfix operators follow a primary expression. The postfix operators are listed in the following table.

Postfix Operators

Operator Name

Operator Notation

Subscript operator

[ ]

Function call operator

( )

Explicit type conversion operator

type-name( )

Member access operator

. or –>

Postfix increment operator

++

Postfix decrement operator

––

The following syntax describes possible postfix expressions:

primary-expression 
postfix-expression[expression]postfix-expression(expression-list<SUB>opt</SUB> )simple-type-name(expression-list<SUB>opt</SUB> )postfix-expression.namepostfix-expression–>namepostfix-expression++postfix-expression––cast-keyword < typename > (expression )typeid ( typename )

The postfix-expression above may be a primary expression or another postfix expression. See primary expressions. Postfix expressions group left to right, thus allowing the expressions to be chained together as follows:

func(1)->GetValue()++

In the above expression, func is a primary expression, func(1) is a function postfix expression, func(1)->GetData is a postfix expression specifying a member of the class, func(1)->GetData() is another function postfix expression, and the entire expression is a postfix expression incrementing the return value of GetData. The meaning of the expression as a whole is "call func passing 1 as an argument and get a pointer to a class as a return value. Then call GetValue() on that class, then increment the value returned.

The expressions listed above are assignment expressions, meaning that the result of these expressions must be an r-value.

The postfix expression form

simple-type-name ( expression-list )

indicates the invocation of the constructor. If the simple-type-name is a fundamental type, the expression list must be a single expression, and this expression indicates a cast of the expression's value to the fundamental type. This type of cast expression mimics a constructor. Because this form allows fundamental types and classes to be constructed using the same syntax, this form is especially useful when defining template classes.

The cast-keyword is one of dynamic_cast, static_cast or reinterpret_cast. More information may be found in dynamic_cast, static_cast and reinterpet_cast.

The typeid operator is considered a postfix expression. See typeid operator.

See Also

Concepts

Types of Expressions