确定没有其虚拟表指针的对象的大小 [英] Determine the size of object without its virtual table pointers
本文介绍了确定没有其虚拟表指针的对象的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个通用的方法(不依赖于平台)在编译时获取内存中类对象的大小,而不计数vtable指针?
Is there a generic way (not platform dependent) to get at compile time the size of a class object in the memory, without counting the vtable pointers?
推荐答案
正在请求一个可移植的方式:
As you are asking for a portable way:
class MyClass
{
private:
struct S
{
DataMemberType1 dataMember1;
...
DataMemberTypeN dataMemberN;
} m;
public:
static const size_t MemberSize = sizeof(S);
};
这篇关于确定没有其虚拟表指针的对象的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文