由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++里面 class的数据成员的顺序是什么样的?
相关主题
c++ question请问可以这样定义struct吗?
What does the default constructor do?[合集] more interview questions
Marshal C++ struct to C# structC++一个string的小问题
给几个teacherwei代码的评审意见吧What problem can occur when dynamically allocated classes
菜鸟请教C问题C++ Interview Question
effective C++里的memory pool 一问:内存分配问题
why do we still use dynamic allocation?a small question about c++ memory allocation
关于内存泄漏请教关于allocator member function 的问题
相关话题的讨论汇总
话题: class话题: c++话题: 顺序话题: members话题: 里面
进入Programming版参与讨论
1 (共1页)
s*****k
发帖数: 604
1
C++标准里面对这个有规定吗?
比如先private再public,类似这样的规定
好像C里面struct里的各个field是不能变顺序的,
在内存里就是按着声明的顺序排的。有些语言可以
根据需要(例如alignment)调整各个field的顺序
c**a
发帖数: 316
2
声明的顺序吧。

【在 s*****k 的大作中提到】
: C++标准里面对这个有规定吗?
: 比如先private再public,类似这样的规定
: 好像C里面struct里的各个field是不能变顺序的,
: 在内存里就是按着声明的顺序排的。有些语言可以
: 根据需要(例如alignment)调整各个field的顺序

t****t
发帖数: 6806
3
Nonstatic data members of a (non-union) class declared without an
intervening access-specifier are allocated so that later members have
higher addresses within a class object. The order of allocation of
nonstatic data members separated by an access-specifier is unspecified
(_class.access.spec_). Implementation alignment requirements might
cause two adjacent members not to be allocated immediately after each
other; so might requirements for space for managing virtual f
a****l
发帖数: 8211
4
I believe the point of making class is exactly that you should not try to
figure out where they are in the memory.

【在 s*****k 的大作中提到】
: C++标准里面对这个有规定吗?
: 比如先private再public,类似这样的规定
: 好像C里面struct里的各个field是不能变顺序的,
: 在内存里就是按着声明的顺序排的。有些语言可以
: 根据需要(例如alignment)调整各个field的顺序

s*****k
发帖数: 604
5
我以前用过一个数值计算的C++的库,里面也用到lapack,
那里面就是假设 std::complex 和 fortan77里面的
complex16 的 memory layout是一样的。好像在大部分平台上
也确实如此。

【在 a****l 的大作中提到】
: I believe the point of making class is exactly that you should not try to
: figure out where they are in the memory.

1 (共1页)
进入Programming版参与讨论
相关主题
请教关于allocator member function 的问题菜鸟请教C问题
在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)effective C++里的memory pool 一问:
关于C/C++里的Static variable的memory allocation/initializawhy do we still use dynamic allocation?
什么是OS Memory management and heap structure?关于内存泄漏
c++ question请问可以这样定义struct吗?
What does the default constructor do?[合集] more interview questions
Marshal C++ struct to C# structC++一个string的小问题
给几个teacherwei代码的评审意见吧What problem can occur when dynamically allocated classes
相关话题的讨论汇总
话题: class话题: c++话题: 顺序话题: members话题: 里面