简体   繁体   中英

Binary encapsulation in C++?

1) What is binary encapsulation in c++, and does c++ support binary encapsulation?

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?

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. 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.

To clarify: Syntactic encapsulation is when you use the language syntax to encapsulate. In C++ this would be the private/protected keywords.

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++. See this wiki page on Opaque pointers for more info.

  1. There are 2 types of Encapsulation Syntactical Encapsulation & Binary Encapsulation.
  2. C ++ Doesn't support Binary Encapsulation.It only supports Syntactical Encapsulation.
  3. Binary Encapsulation is supported by COM.
  4. Best example of Binary Encapsulation is QueryInterface(void **) method of COM.
  5. As this method takes one output parameter as void **. So it's double redirection as pointer is void **.
  6. To get more details on this read Inside COM by Don Bix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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