Files
2025-10-25 03:02:53 +03:00

77 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[conv.mem]
# 7 Expressions [[expr]](./#expr)
## 7.3 Standard conversions [[conv]](conv#mem)
### 7.3.13 Pointer-to-member conversions [conv.mem]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1075)
A [null pointer constant](conv.ptr#def:constant,null_pointer "7.3.12Pointer conversions[conv.ptr]") can be converted to a
pointer-to-member
type; the result is the [*null member pointer value*](#def:value,null_member_pointer "7.3.13Pointer-to-member conversions[conv.mem]") of that type and is distinguishable from any pointer to member not
created from a null pointer constant[.](#1.sentence-1)
Such a conversion is called a [*null member pointer conversion*](#def:conversion,null_member_pointer "7.3.13Pointer-to-member conversions[conv.mem]")[.](#1.sentence-2)
The conversion of a null pointer
constant to a pointer to member of cv-qualified type is a single
conversion, and not the sequence of a pointer-to-member conversion
followed by a qualification conversion ([[conv.qual]](conv.qual "7.3.6Qualification conversions"))[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1090)
A prvalue of type “pointer to member of B of type cvT”, where B is a class type, can be converted to
a prvalue of type “pointer to member of D of type cvT”, where D is a complete class derived ([[class.derived]](class.derived "11.7Derived classes"))
from B[.](#2.sentence-1)
If B is an
inaccessible ([[class.access]](class.access "11.8Member access control")),
ambiguous ([[class.member.lookup]](class.member.lookup "6.5.2Member name lookup")), or virtual ([[class.mi]](class.mi "11.7.2Multiple base classes")) base
class of D, or a base class of a virtual base class ofD, a program that necessitates this conversion is ill-formed[.](#2.sentence-2)
If class D does not contain the original member and
is not a base class of the class containing the original member,
the behavior is undefined[.](#2.sentence-3)
Otherwise,
the result of the conversion refers to the same member as the pointer to
member before the conversion took place, but it refers to the base class
member as if it were a member of the derived class[.](#2.sentence-4)
The result refers to
the member in D's instance of B[.](#2.sentence-5)
Since the result has
type “pointer to member of D of type cv T”,
indirection through it with a D object is valid[.](#2.sentence-6)
The result is the same
as if indirecting through the pointer to member of B with theB subobject of D[.](#2.sentence-7)
The null member pointer value is
converted to the null member pointer value of the destination
type[.](#2.sentence-8)[46](#footnote-46 "The rule for conversion of pointers to members (from pointer to member of base to pointer to member of derived) appears inverted compared to the rule for pointers to objects (from pointer to derived to pointer to base) ([conv.ptr], [class.derived]). This inversion is necessary to ensure type safety. Note that a pointer to member is not an object pointer or a function pointer and the rules for conversions of such pointers do not apply to pointers to members. In particular, a pointer to member cannot be converted to a void*.")
[46)](#footnote-46)[46)](#footnoteref-46)
The rule for conversion of pointers to members (from pointer to member
of base to pointer to member of derived) appears inverted compared to
the rule for pointers to objects (from pointer to derived to pointer to
base) ([[conv.ptr]](conv.ptr "7.3.12Pointer conversions"), [[class.derived]](class.derived "11.7Derived classes"))[.](#footnote-46.sentence-1)
This inversion is
necessary to ensure type safety[.](#footnote-46.sentence-2)
Note that a pointer to member is not
an object pointer or a function pointer
and the rules for conversions
of such pointers do not apply to pointers to members[.](#footnote-46.sentence-3)
In particular, a pointer to member cannot be converted to avoid*[.](#footnote-46.sentence-4)