Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#ccccff
langcpp
#include <cstddef>

struct D {
  virtual void f() {}
  struct InnerStandardLayout {
    int i;
  } inner;
};

void f() {
  size_t off = offsetof(D::InnerStandardLayout, i);
  // ...
}

...