4.1 KiB
[dcl.mptr]
9 Declarations [dcl]
9.3 Declarators [dcl.decl]
9.3.4 Meaning of declarators [dcl.meaning]
9.3.4.4 Pointers to members [dcl.mptr]
The component names of a ptr-operator are those of its nested-name-specifier, if any.
In a declarationTD whereD has the form
nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt D1
and thenested-name-specifier designates a class, and the type of the contained declarator-id in the declarationTD1 is âderived-declarator-type-listTâ, the type of the declarator-id inD is âderived-declarator-type-list cv-qualifier-seq pointer to member of classnested-name-specifier of typeTâ.
The optional attribute-specifier-seq ([dcl.attr.grammar]) appertains to the pointer-to-member.
The nested-name-specifier shall not designate an anonymous union.
[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.
The declaration ofpmd is well-formed even thoughX has no members of typedouble.
Similarly, the declaration ofpmc is well-formed even thoughY is an incomplete type.
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]
A pointer to member shall not point to a static member of a class ([class.static]), a member with reference type, or âcv voidâ.
[Note 1:
See also [expr.unary] and [expr.mptr.oper].
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.
There is no âreference-to-memberâ type in C++.
â end note]