gpt4 book ai didi

c++ - C++ 中的二进制封装?

转载 作者:行者123 更新时间:2023-11-27 23:21:15 25 4
gpt4 key购买 nike

1)c++中什么是二进制封装,c++是否支持二进制封装?

我做了一些搜索,但我发现的只是封装,大致就是将数据和方法包装在一个类中。

2)那么封装和二进制封装有什么区别呢?

最佳答案

引自 this text应该把事情弄清楚:

Whereas C++ does support syntactic encapsulation via its private and protected keywords, the C++ draft standard has no notion of binary encapsulation. This is because the compilation model of C++ requires the client’s compiler to have access to all information regarding object layout in order to instantiate an instance of a class or to make nonvirtual method calls. This includes information about the size and order of the object’s private and protected data members.

澄清一下:句法封装就是用语言的句法来封装。在 C++ 中,这将是 private/protected 关键字。

我通过this thread找到了文本其中也有对该概念的简短解释。

编辑:

正如下面所指出的,C++ 中可以存在二进制封装。参见 this wiki page在不透明指针上获取更多信息。

关于c++ - C++ 中的二进制封装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com