sizeof *这个对象 [英] sizeof *this object
本文介绍了sizeof *这个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
#include <cstdio>
class myc {
int dummy;
public:
int si(){return sizeof(*this);}
};
class d_myc : public myc {
int d_dummy;
};
int main() {
myc a;
d_myc b;
printf("%d %d\n%d %d", a.si(), b.si(), sizeof(a), sizeof(b));
return 0;
}
输出:
4 4
4 8
4 8
4 8
为什么我的期望错了?
推荐答案
/ code>在编译时解决,而不是运行时解析。因此
sizeof(* this)
等效于 sizeof(myc)
。
这篇关于sizeof *这个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文