how to compute offset of data member at compile time (virtual class)
John Gateley
gateley@jriver.com
Thu Oct 25 16:57:00 GMT 2007
I need to compute the offset of a data member at compile time.
The class has virtual functions, and so the offsetof macro does
not work (why?). Is there a way to do this?
My example (compiler error on the printf line):
#include <stdio.h>
#include <stddef.h>
class Foo {
public:
virtual void Bar();
int m_x;
char m_y;
char z[30];
float w;
};
int main(int argc, char **argv)
{
printf("%d\n", offsetof(Foo, w));
}
Thanks,
j
--
John Gateley <gateley@jriver.com>
More information about the Gcc-help
mailing list