[expr.mptr.oper] (original) (raw)

7 Expressions [expr]

7.6 Compound expressions [expr.compound]

7.6.4 Pointer-to-member operators [expr.mptr.oper]

The pointer-to-member operators ->* and .* group left-to-right.

The binary operator .* binds its second operand, which shall be a prvalue of type “pointer to member of T” to its first operand, which shall be a glvalue of class T or of a class of which T is an unambiguous and accessible base class.

The result is an object or a function of the type specified by the second operand.

The binary operator ->* binds its second operand, which shall be a prvalue of type “pointer to member of T” to its first operand, which shall be of type “pointer to U” where U is either T or a class of which Tis an unambiguous and accessible base class.

The expression E1->*E2 is converted into the equivalent form(*(E1)).*E2.

If the result of E1 is an object whose type is not similar to the type of E1, or whose most derived object does not contain the member to whichE2 refers, the behavior is undefined.

The expression E1 is sequenced before the expression E2.

The restrictions on cv-qualification, and the manner in which the cv-qualifiers of the operands are combined to produce the cv-qualifiers of the result, are the same as the rules forE1.E2 given in [expr.ref].

[Note 1:

It is not possible to use a pointer to member that refers to amutable member to modify a const class object.

For example,struct S { S() : i(0) { } mutable int i;};void f() { const S cs;int S::* pm = &S::i; cs.*pm = 88; }

— _end note_]

If the result of .* or ->* is a function, then that result can be used only as the operand for the function call operator().

[Example 1:

(ptr_to_obj->*ptr_to_mfct)(10);calls the member function denoted by ptr_to_mfct for the object pointed to by ptr_to_obj.

— _end example_]

In a .* expression whose object expression is an rvalue, the program is ill-formed if the second operand is a pointer to member function whose ref-qualifier is &, unless its cv-qualifier-seq is const.

In a .*expression whose object expression is an lvalue, the program is ill-formed if the second operand is a pointer to member function whose ref-qualifier is &&.

The result of a .* expression whose second operand is a pointer to a data member is an lvalue if the first operand is an lvalue and an xvalue otherwise.

The result of a .* expression whose second operand is a pointer to a member function is a prvalue.