I did however circumvent it with an int typecast from a pointer to member. Like:
// instead of:
// I have:
This works under GNU C++ (Linux&MinGW) and under Borland C++ Compiler (just checked). If I recall correctly, the cast is guaranteed to evaluate to the byte offset, but I didn't really check it with the C++ draft. [EDIT: I just checked and found that this cast is not on the guaranteed casts list, so a compiler can return any integer it wants. So, you unfortunately can't use it if you want to be completely on the safe side.]
Another way to circumvent it is having:
Class *foo = new Class;
int byteOffset = (char*)(&foo->member) - (char*)(foo);
This should be perfectly portable, but is rather inconvenient. I will however try to check if the first method is really portable and standard.
If the first way is not standard, you could have a macro in your code that would evaluate to member-pointer-cast under GNU and differently other compilers.
I tried to develop a solution based on templates and the second solution above - but I ended up only, hm, half solving the problem. The function getByteOffset works, but calling it is a pain, something like:
getByteOffset(new Class(3,3), (&Class::member))
This could be made into a macro, but only for objects that have an implicit constructor (Class::Class(), I'm not sure if it's actually called "implicit"). Other objects would need parameters to create a new object.[Edited by - krajzega on July 28, 2004 11:14:21 AM]
That is really only a warning, but offsetof returns the correct values, so I didn't post it as a problem in the forum.