TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
.* operator is the C++ pointer-to-member access operator used to bind a pointer-to-member to a specific object instance. It evaluates to the actual member (data or function) of the left-hand object designated by the right-hand pointer-to-member.
Operands and Type Requirements
- Left Operand: Must be an object of class type
T(or a class derived fromT, providedTis an unambiguous and accessible base class of the derived class). It can be an lvalue or an rvalue. - Right Operand: Must be a pointer-to-member of class
T. It cannot be a standard pointer; it must be declared using theType T::*syntax.
Pointer-to-Data-Member Mechanics
When the right operand is a pointer to a data member, the.* operator computes the memory offset of that member relative to the base address of the left operand.
The value category of the result depends on the left operand:
- If the object is an lvalue, the result is an lvalue.
- If the object is an rvalue, the result is an xvalue (expiring value).
- The cv-qualification (const/volatile) of the result is the union of the cv-qualifiers of the left operand and the type pointed to by the pointer-to-member. Because a pointer-to-member does not retain the
mutableproperty of a data member, accessing amutablemember of aconstobject via.*yields aconstresult (unlike direct.member access).
Pointer-to-Member-Function Mechanics
When the right operand is a pointer to a member function, the.* operator yields a special, un-nameable bound member function entity.
This entity has strict syntactic limitations: it must be immediately invoked using the function call operator (). It cannot be assigned to a variable, cast, or passed as an argument.
Because the function call operator () has higher precedence than the .* operator, the entire .* expression must be enclosed in parentheses.
Operator Characteristics
- Precedence: The
.*operator has a precedence level of 4, which is lower than the member access operator.and the function call operator(), but higher than multiplication*. - Associativity: Left-to-right.
- Overloadability: The
.*operator cannot be overloaded. This guarantees that its semantics regarding offset calculation and member binding remain strictly defined by the compiler. (Note: Its counterpart,->*, can be overloaded). - Polymorphism: If the right operand points to a virtual member function, the
.*operator respects dynamic dispatch. The actual function invoked will be resolved at runtime based on the dynamic type of the left operand.
Master C++ with Deep Grasping Methodology!Learn More





