C++ 中用户定义类的大小
Size of user defined class in c++
有没有计算c++类大小的方法。 当我创建下面类的对象时,对象的大小为 24 字节。
class student
{
student* pointer;
char * c;
student* AnotherPointer;
class SubClass
{
int a,b;
};
};
现在从学生类中删除子类,我仍然得到学生类对象的大小为 24。 为什么它没有改变??
class student
{
student* pointer;
char * c;
student* AnotherPointer;
};
有没有计算 c++ 类大小的方法。
可以使用sizeof
运算符获取类的大小或任何其他类型。例如:
std::cout << sizeof(student);
删除子类
请注意,名为Subclass
的类不是"子类"。它是一个嵌套类。
为什么它没有改变??
因为您没有对类的子对象进行任何更改。嵌套类不是子对象。事实上,它根本不是一个对象——它是一种类型。
相关文章:
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- Visual C++(VS2017)中用户定义的转换不明确
- 使用用户定义的参数调用future/async并调用类方法
- 带有用户定义类的c++折叠表达式
- g++用户定义的动态链接库上的全局new和delete运算符
- 直接在 unordered_map 的方法中使用哈希,而不是生成哈希的用户定义对象
- 修改"std::set"中用户定义类型的值
- 参数包构造函数在类模板中隐藏用户定义的转换
- MAKE:找不到包含的用户定义的头文件?
- C++:用户定义的显式类型转换函数错误
- 是否有解决方法可以在 c++ 中为 short 定义用户定义的文字?
- 从 QAbstractItemModel 返回自定义用户类型
- 无法引用自定义用户控件
- Lua:为自定义用户数据提供一个字符串方法
- 是否可以在visualstudio调试窗口中定义用户定义的变量
- 如何在编写自定义用户操作时引用内置操作
- C++自定义用户输入调用变量
- 不能定义用户定义的字面值