Do you have a "member pointer" for a union member?

All the descriptions I can find speak of a "member pointer" in the context of the class. Unions are very similar to structures and, in particular, have members. Do you have a pointer to these members?

eg.

union x { int a; float b; }; int x::*p = &x::a; 

I am not talking about a pointer to a union as a whole, it indicates membership in a union, etc. p in the above example will indeed be an offset, obviously, of size 0. I will need this construction to answer this question .

+4
source share
1 answer

ยง3.9.2 / 1: composite types can be constructed in the following ways: ... pointers to non-static 50 members of a class that identify members of a given type in objects of this class,

ยง8.3.3 / 1: In a TD declaration, where D has the form ... and the nested name specifier denotes a class, ...

ยง5.3.1 / 3: The result of the unary operator & is a pointer to its operand. The operand must be lvalue or identified-id. If the operand is a qualified identifier that names the non-static member m some class C with type T , the result is of type "pointer to a member of class C of type T" and is the notation prvalue C::m .

And, of course, ยง9.5 / 5: A union is a class defined using the key of the union class ...

(in ยง 3.3.2 / 1 it is also mentioned: unions that are classes ...)

There is no mention that the class cannot be a union, so yes, you can form such a type and value of PTM.

+5
source

All Articles