问题
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?
回答1:
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);
};
回答2:
Use sizeof
on this class
, it doesn't include size of the vtable
just the pointer.
来源:https://stackoverflow.com/questions/28433973/determine-the-size-of-object-without-its-virtual-table-pointers