Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有一种通用方法(不依赖于平台)在编译时获取内存中类对象的大小,而不计算 vtable 指针?
当您要求一种便携式方式时:
class MyClass { private: struct S { DataMemberType1 dataMember1; ... DataMemberTypeN dataMemberN; } m; public: static const size_t MemberSize = sizeof(S); };
sizeof在 this 上使用class,它不包括vtable指针的大小。
sizeof
class
vtable