I have some template classes that are separated into header files and implementation files:
// MyTemplate.h
template<class T>
class MyTemplate {
public:
void Foo();
};
// MyTemplate.cpp
#include "MyTemplate.h"
template<class T>
void MyTemplate<T>::Foo() {
// ...
}
To use MyTemplate
in another translation unit I can #include
the implementation file:
#include "MyTemplate.cpp"
template class MyTemplate<int>;
This way I get to:
- Keep the interface and implementation in separate files.
- Not have to maintain a list of all template instantiations in the implementation file.
I am in the process of converting to C++ modules. Is there any way to achieve the same with modules, when I should no longer use #include
?