Bob Hairgrove wrote:[color=blue]
> On 14 Dec 2005 09:12:58 -0800,
roberts.noah@gmail.com wrote:
>[color=green]
> >
> >David Harmon wrote:[color=darkred]
> >> On Tue, 13 Dec 2005 17:24:21 -0700 in comp.lang.c++, "Dave"
> >> <better_cs_now@yahoo.com> wrote,
> >> >
> >> >I have no guarantee that a pointer-to-member is implemented as a simple
> >> >offset. It can be anything at all at the discretion of the compiler
> >> >implementor!
> >>
> >> Indeed it is (probably) not a simple offset, and cannot be in order
> >> to do everything in the presence of non-POD object features. But it
> >> does have "the same effect" for many of the purposes where you might
> >> legitimately use an offset in old C.
> >>
> >> I am sure you do not want to violate object encapsulation, type
> >> safety, or anything like that. So, what are you trying to
> >> accomplish?[/color]
> >
> >I had a problem the other day where I thought I was going to need the
> >old offset macro. The problem was that I had a struct that had several
> >structs representing different types of devices and inside of these
> >structs where different fields for each struct. I wanted to have a
> >variable store a pointer to one of those fields but I needed in
> >relation to the original struct. AFAICT there is no way to define a
> >pointer to a member of a member of a struct or class so I couldn't use
> >member pointers.
> >
> >You can do:
> >
> >int Outer::Inner::*x = & Outer::Inner::var
> >
> >But how would you do:
> >
> >int Outer::*x = &Outer::Inner::var
> >
> >At any rate I was dealing with a POD so the whole address of member of
> >null macro would work.
> >
> >However, instead of doing this I decided to refactor the structure of
> >the classes I needed to track. I ended up with a better and more
> >elegant sollution.[/color]
>
> If the innermost member is a data member, just use a regular pointer.[/color]
For some reason when I delete things and make new ones stuff tends to
get moved around and I haven't quite established why, but my pointers
become invalid at that point!! Sometimes when my pointers are created
there is no variable of type "Outer" and for some reason my program
blew up when I tried to get the direct addresses of its contents. Very
unsettling.
Question: Why is it that people assume your an idiot when you post to
usenet and don't spell out every obvious detail? Obviously if a simple
direct address to a variable would do there is no need to try wierd
shit like member pointers... I'm not a COMPLETE moron.