Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For C++ it's an implementation issue.</p> <p>The C++ compiler must be able to generate code that uses a class by only seeing the class declaration and not the implementation. One very important thing that is needed by the compiler is the size of an instance of the class because among other things C++ handles sub-objects in objects by embedding and not by storing a reference to a separate object. To be able to build an object (e.g. <code>struct X { Y y; Z z; }</code>) the size of all sub-objects (e.g. <code>Y</code> and <code>Z</code>) must be known in advance.</p> <p>A workaround for this problem is to use <a href="http://www.gotw.ca/publications/mill05.htm" rel="nofollow">the "pimpl" pattern (also named the "compiler firewall" pattern)</a> that allows you to keep all internal details hidden from the users of a class. This unfortunately carries some runtime extra cost with it but most the time it's a negligible one. With this approach the public object will always have the size of a pointer and all data in the instance will be accessed using an extra indirection... the advantage is that you can add private data members and users of the class don't need to be recompiled (and if your class is for example in a DLL this allows to maintain even binary compatibility).</p> <p>Being able to declare just private methods (no data) in the implementation part would have been possible without any added complexity on the compiler, but C++ designer thought it was better to keep one single declaration for a class instead.</p> <p>Actually even just adding a private method may affect the size of the a class instance in many implementations (e.g. if the private method is the only virtual one in the class).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload