关于在C和C ++中使用offsetof? [英] About offsetof usage in C and C++?
本文介绍了关于在C和C ++中使用offsetof?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C中,我看到一些使用offsetof来计算结构中的成员到其开始的偏移量?
In C, I saw some usage of offsetof to calculate the offset of a member in the structure to its beginning?
仍建议在C ++中使用?
Is it still recommended to use in C++? Any other way to do this without this macro?
推荐答案
C ++有指向成员的指针。这些类似于偏移,但是(1)类型安全和(2)更通用 - 它们也使用方法,基类等。
C++ has pointers to members. These are similar to offsets, but (1) typesafe and (2) more generic - they also work with methods, on base classes, etc.
这篇关于关于在C和C ++中使用offsetof?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文