Steve said:
Then I need an S1::* pointer, not an S2B::* pointer.
Why is that logical?
I don't see why you're trying to make out that I want something I don't.
Look, if I have an S2B object, s2b, we all agree that I can write,
s2b.s.x1 = 1;
s2b.x3 = 2;
On any Earthlike planet, the compiler is going to generate structurally
identical code for both cases - add a fixed offset to the object base
address to get the destination address, load a value into that address.
All I'm after is to be able to have a pointer, p, which can duplicate
the effect of either of those statements via the expression 's2b.*p'.
If I also have,
S1 *ps1 = &s2b.s;
I neither expect nor want to be able to use the expression 'ps1->*p' and
I don't understand why you seem to be insisting I do.
I would suggest focussing on the capabilities of the pointer you are
asking for - and not on the relatively simple manner with which you
intend to use it. You're essentially asking for a yacht which you
intend to use as a rowboat. The capabililties of a member pointer (and
by extension a member member pointer) have no relation to the actual
definition of the class to which it belongs. So even though there may
be only one data member to which a particular type of member pointer
can legitimately point to, the member pointer has to assume that there
are any number of matching members that it could point to and plan its
storage accordingly.
The pointer which you are asking for is one that must be able to point
to any int member anywhere in an S2B member located anywhere in an S1
struct. Those two "anywhere" requirements are twice the one "anywhere"
requirement for a standard member pointer. And while it is true that
your use of this member member pointer doesn't do justice to its
wideranging addressing capability, there is no way for the compiler to
slim down this type of pointer simply due to that fact. These pointers
can have only one format, and that format must be able to handle the
full requirements for that pointer type.
So the disconnect in this discussion I would say stems from the fact
that your relatively simple use of the pointer does not adequately
demonstrate the more complex cases which the same type of pointer must
(unfortunately) also be able to handle.
Greg