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

80 lines
4.1 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.

[dcl.mptr]
# 9 Declarations [[dcl]](./#dcl)
## 9.3 Declarators [[dcl.decl]](dcl.decl#dcl.mptr)
### 9.3.4 Meaning of declarators [[dcl.meaning]](dcl.meaning#dcl.mptr)
#### 9.3.4.4 Pointers to members [dcl.mptr]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L3354)
The component names of a [*ptr-operator*](dcl.decl.general#nt:ptr-operator "9.3.1General[dcl.decl.general]") are
those of its [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3Qualified names[expr.prim.id.qual]"), if any[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L3359)
In a declarationTD whereD has the form
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3Qualified names[expr.prim.id.qual]") * [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt [*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]")opt D1
and the[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3Qualified names[expr.prim.id.qual]") designates a class,
and the type of the contained [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1General[dcl.decl.general]") in the declarationTD1 is “*derived-declarator-type-list*T”,
the type of the [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1General[dcl.decl.general]") inD is “*derived-declarator-type-list* [*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]") pointer to member of class[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3Qualified names[expr.prim.id.qual]") of typeT”[.](#2.sentence-1)
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]") ([[dcl.attr.grammar]](dcl.attr.grammar "9.13.1Attribute syntax and semantics")) appertains to the
pointer-to-member[.](#2.sentence-2)
The [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3Qualified names[expr.prim.id.qual]") shall not designate an anonymous union[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L3386)
[*Example [1](#example-1)*:
struct X {void f(int); int a;};struct Y;
int X::* pmi = &X::a;void (X::* pmf)(int) = &X::f;double X::* pmd;char Y::* pmc; declarespmi,pmf,pmd andpmc to be a pointer to a member ofX of typeint,
a pointer to a member ofX of typevoid(int),
a pointer to a member ofX of typedouble and a pointer to a member ofY of typechar respectively[.](#3.sentence-1)
The declaration ofpmd is well-formed even thoughX has no members of typedouble[.](#3.sentence-2)
Similarly, the declaration ofpmc is well-formed even thoughY is an incomplete type[.](#3.sentence-3)
pmi andpmf can be used like this:X obj;// ... obj.*pmi = 7; // assign 7 to an integer member of obj(obj.*pmf)(7); // call a function member of obj with the argument 7
— *end example*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L3446)
A pointer to member shall not point to a static member
of a class ([[class.static]](class.static "11.4.9Static members")),
a member with reference type,
or
“cv void”[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L3453)
[*Note [1](#note-1)*:
See also [[expr.unary]](expr.unary "7.6.2Unary expressions") and [[expr.mptr.oper]](expr.mptr.oper "7.6.4Pointer-to-member operators")[.](#5.sentence-1)
The type “pointer to member” is distinct from the type “pointer”,
that is, a pointer to member is declared only by the pointer-to-member
declarator syntax, and never by the pointer declarator syntax[.](#5.sentence-2)
There is no “reference-to-member” type in C++[.](#5.sentence-3)
— *end note*]