Author: Stephan Bergmann. Last changed: $Date: 2004/10/28 13:05:15 $.

How to design C++ classes that are part of the SDK salhelper/cppuhelper API

The following list gives instructions how to design a C++ class that shall be part of the API of either salhelper or cppuhelper (i.e., of any SDK shared library that has a C++ API that is not all-inline). The motivating force behind those instructions is to minimize the amount of global symbols (especially weak ones). The list also explains exactly which symbols corresponding to a class to export on which platform; see SDK Dynamic Library Versioning for details about adding exported symbols to dynamic libraries.

  1. Never define inline functions. (Neither explicitly nor implicitly, by defining a function within its class. Inline functions, especially constructors and destructors, often make it necessary to export certain symbols that could otherwise be left unexported.)

  2. Make sure that the compiler does not declare any implicit functions. (To avoid any implicitly defined inline functions, see point 1. Potential implicit functions are default constructors, copy constructors, destructors, and copy assignment operators. The easiest way to avoid them is to declare a destructor, at least one copy constructor, and at least one copy assignment operator for each class; those declared functions that shall not be available can be declared private and left undefined.)

  3. Define every destructor that is declared. (Even a destructor that is declared pure virtual, to avoid any implicitly defined inline functions, see point 1.)

  4. If a class type (possibly cv-qualified, and possibly nested within pointer or reference types) is ever used either

    then declare its destructor virtual. (To have a dedicated place where RTTI for that class is generated. Since in general you cannot control the ways a class is used, the best advice probably is to do this for each class that is intended to be either used as an exception or subclassed.)

  5. If the destructor of a class is declared virtual, declare the destructors of all its base classes virtual. (To have a dedicated place where RTTI for the base classes is generated, which is referenced by the RTTI for the derived class. Since in general you cannot control the ways a class is used, the best advice probably is to do this for each class that is intended to be subclassed.)

  6. Special symbols to be exported for GCC 3:

  7. Special symbols to be exported for Sun C++ 5:

  8. Special symbols to be exported for Microsoft Visual C++: