David said:
On Tue, 13 Dec 2005 17:24:21 -0700 in comp.lang.c++, "Dave"
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?
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.