I have a system that looks something like this:
Master.h
extern const Activators[2];
Master.cpp
#include <TypeOne.h>
#include <TypeTwo.h>
const Activators[2] = { &TypeOne::Create, &TypeTwo::Create };
Where you can imagine TypeOne and TypeTwo are classes with a static Create method that returns a new instance.
I'm looking for a way to decompose this system such that there doesn't need to be a single file that creates a link-time dependency on all of the types.
I'd like to be able to link together a unit test with just TypeOne's object file and a version of the static Activators array that is only filled with the function pointer to TypeOne's Create method.
Is there a way in C++ to create a statically-defined array and then fill individual slots in that array across compilation units? Ideally I'd be able to have something like this:
Master.cpp
const Activators[2];
TypeOne.cpp
Activators[0] = &TypeOne::Create;
TypeTwo.cpp
Activators[1] = &TypeTwo::Create;