Currently, offsetof
works only with standard layout types. However, I've never understood this limit. Sure, for types with virtual inheritance, offsetof
cannot work. But for types without virtual inheritance, it could. I know, the standard allows non-standard layout types to have differing offsets of members for each instance. But, I've never heard of any compiler implementations which uses this. Why would it do something like this?
All the compilers I know, for types without virtual inheritance, offsets of members are compile-time constants.
So the question is:
offsetof
?(I've read a lot of related answers here in stackoverflow, and discussions of this at various places, but I haven't found the reason of this).
The arbitrary nature of this restriction was discussed in July by the committee. It's not in the working paper yet, but I believe it will be relaxed (to this degree, at least) in C++20.
Relax the requirements to what? offsetof
is okay to use except when it gives incorrect results?
The way to access selected data members of a C++ object is with a pointer to data member.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With