#include<iostream>
using namespace std;
class student
{
public:
int a;
char *p;
void fun1();
void fun2();
static void fun3();
virtual void fun4();
};
int main()
{
cout << sizeof(student) << endl;
system("pause");
return 0;
}
输出结果是12字节
为什么是12字节呢,因为类里面有虚函数,类里面生成一个虚指针,指针是4个字节,所以是12字节
本文通过一个简单的C++示例程序解释了类中成员变量和虚函数如何影响类实例的大小,并具体说明了虚指针的存在及其占用的空间。
3192

被折叠的 条评论
为什么被折叠?



