除了可访问性,什么其他访问限定符影响? [英] Besides accessibility, what else access-specifiers effects?

查看:123
本文介绍了除了可访问性,什么其他访问限定符影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了对可见或不是派生类的正常解释外,它们之间有什么其他区别吗?

Besides the normal explenation of being visible or not to derived classes, is their any other difference?

如果你使它更加明显,

If you make it more visible, is it taking more or less memory, does it slow thing down or...?

推荐答案

除了派生类以外的成员的可访问性,访问说明符可能会影响对象布局。

Apart from the accessibility of members outside or to the derived classes, access specifiers might affect the object layout.

引用我的其他答案

通常,数据成员的内存地址按照它们定义的顺序增加班上 。但此订单可能在访问说明符( private protected public 。这已在 C ++对象模型中通过 Lippman

Usually, memory address for data members increases in the order they're defined in the class . But this order may be disrupted at any place where the access-specifiers (private, protected, public) are encountered. This has been discussed in great detail in Inside the C++ Object Model by Lippman.

摘录自 C / C ++ Users Journal


编译器不允许这样做
重新排列本身。
标准要求在相同 public :, protected :,或
private:中的
的所有数据必须在该
订单中编译器。 如果
使用访问
说明符来穿插您的数据,编译器将允许
重新安排
访问限定符分隔的
数据块改进布局
这是
为什么有些人喜欢在每个数据
成员前面添加一个访问
说明符。

The compiler isn't allowed to do this rearrangement itself, though. The standard requires that all data that's in the same public:, protected:, or private: must be laid out in that order by the compiler. If you intersperse your data with access specifiers, though, the compiler is allowed to rearrange the access-specifier-delimited blocks of data to improve the layout, which is why some people like putting an access specifier in front of every data member.

有趣的是,不是吗?

这篇关于除了可访问性,什么其他访问限定符影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆