简体   繁体   English

C++中的二进制封装?

[英]Binary encapsulation in C++?

1) What is binary encapsulation in c++, and does c++ support binary encapsulation? 1)c++中什么是二进制封装,c++支持二进制封装吗?

I did some searching but all that I found was just encapsulation, which roughly is nothing but wrapping of data and methods in a class.我做了一些搜索,但我发现的只是封装,大致就是将数据和方法包装在一个类中。

2) So what is the difference between encapsulation and binary encapsulation? 2)那么封装和二进制封装有什么区别呢?

A quote from this text should clear things up: 这段文字的引述应该可以解决问题:

Whereas C++ does support syntactic encapsulation via its private and protected keywords, the C++ draft standard has no notion of binary encapsulation.尽管 C++ 确实通过其私有和受保护关键字支持句法封装,但 C++ 草案标准没有二进制封装的概念。 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.这是因为 C++ 的编译模型要求客户端的编译器能够访问有关对象布局的所有信息,以便实例化类的实例或进行非虚拟方法调用。 This includes information about the size and order of the object's private and protected data members.这包括有关对象的私有和受保护数据成员的大小和顺序的信息。

To clarify: Syntactic encapsulation is when you use the language syntax to encapsulate.澄清一下:句法封装是当您使用语言语法进行封装时。 In C++ this would be the private/protected keywords.在 C++ 中,这将是私有/受保护的关键字。

I found the text throughthis thread which has a short explanation of the concept as well.我通过此线程找到了文本,其中也对该概念进行了简短解释。

Edit:编辑:

As pointed out below there can exist binary encapsulation in C++.正如下面所指出的,C++ 中可以存在二进制封装。 See this wiki page on Opaque pointers for more info.有关更多信息,请参阅有关不透明指针的此 wiki 页面

  1. There are 2 types of Encapsulation Syntactical Encapsulation & Binary Encapsulation.有两种类型的封装语法封装和二进制封装。
  2. C ++ Doesn't support Binary Encapsulation.It only supports Syntactical Encapsulation. C++ 不支持二进制封装,只支持语法封装。
  3. Binary Encapsulation is supported by COM. COM 支持二进制封装。
  4. Best example of Binary Encapsulation is QueryInterface(void **) method of COM.二进制封装的最佳示例是 COM 的 QueryInterface(void **) 方法。
  5. As this method takes one output parameter as void **.由于此方法将一个输出参数作为 void **。 So it's double redirection as pointer is void **.所以它是双重重定向,因为指针是 void **。
  6. To get more details on this read Inside COM by Don Bix.要获得有关此内容的更多详细信息,请阅读 Don Bix 的 Inside COM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM