I asked a question entitled automatic registration of object creator function with a macro that has the following example program that runs:
#include
compile and run output is:
> g++ example2.cpp && ./a.out
A::DerivedA constructor
B::DerivedB constructor
C::DerivedC constructor
D::DerivedD constructor