b) You want to serialize a polymorphic derived
class through a pointer to it's base class. This
is OK too, but requires special care. The
problem is that C++ compile/link will generally not
include code which is not specifically referred
to. This occurs when compiling (optimizing out
dead code) and linking - skipping modules not
referred to.
To deal with the second, you have "trick" the
compiler/linker to not discard your code. There
are a couple of ways to do this.
a) Somewhere in the main module, refer to the
derived type in the library. An easy way to
do this is to just create one more function in your
code which refers to the code in the library.
Well, its not that easy because the C++ optimiser
will usually throw away the whole call
if the result isn't used. You can use the "force_include.hpp" to keep this from
happening.