I've got a multi-file project that uses templates.
// Foo.h
template <class T>
class Foo
{
T bar;
};
I have a class (e.g. Cup) and a bunch of subclasses of that class.
// Cup.h
class Cup
{
};
class Chalice : public Cup
{
};
class SippyCup : public Cup
{
};
// ...etc.
In the template's .cpp file, I need to list all possible template implementations to avoid linker errors. I learned this from the C++ FAQ.
//Foo.cpp
template class Foo<Cup>;
template class Foo<Chalice>;
template class Foo<SippyCup>;
// ...etc.
In reality, I have about 20+ subclasses that I'd like to use at any point in my code. In development, I'm constantly creating new subclasses. So each time I create a new one, I have to add it to this growing list in Foo.cpp
.
This is a pain. Is there a way to get around having to list all of these possibilities?