Rearranging, adding, and removing private data members with restrictions

Private data members can be added, removed, and rearranged only if:

They are not referenced from any public or protected inline function that is available to clients or derived classes (part of the Taligent API or SPI).

Doing so doesn't change the offset of a data member that is referenced from any public or protected inline function. It can be hard to determine the impact on portability, as different processors align data differently. It's not clear at this point whether this includes changing the vtable pointer offset. To avoid this latter problem, declare a virtual function before any data members (always place public declarations first).

Doing so doesn't change the size of the class.

If your class is more complex than the very simplest (such as TGRect), take these steps to leave yourself room for future data expansion.

  1. Add a private data member with the following declaration at the beginning of your private declaration section:
      void *fExtension;               // room for growth
  2. Make sure that all of your special member functions (constructors, destructor, assignment, copy constructor, and streaming operators) are defined and not inline.
  3. If you have to add fields in the future, you can make an extension structure and change the declaration to:
      TFooExtension *fExtension;
After that, because TFooExtension's declaration isn't public, you can do whatever you want to it from release to release (see the next section, "Inline functions"). The disadvantage is that it is allocated on the heap. If you have a class for which that is unacceptable, make sure you will never need to grow the size of your class--for example, to add more than one pointer's worth of
reserved space.

NOTE Some C++ runtimes allow you to change sizes of objects without such workarounds, but it is not clear when or if Taligent will support such a feature.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker