...
It is not possible to determine the offset to i within D because D is not a standard-layout class. However, it is possible to make a standard-layout class within D if this functionality is critical to the application, as demonstrated in by this compliant solution:
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <cstddef>
struct D {
virtual void f() {}
struct InnerStandardLayout {
int i;
} inner;
};
void f() {
size_t off = offsetof(D::InnerStandardLayout, i);
// ...
} |
...