...

/

Templates in Modules

Templates in Modules

Explore templates with and without modules.

We'll cover the following...

I often hear the question: How are templates exported by modules? When you instantiate a template, its definition must be available. This is the reason that template definitions are hosted in headers. Conceptually, the usage of a template has the following structure

Without modules

Press + to interact
// templateSum.h
template <typename T, typename T2>
auto sum(T fir, T2 sec) {
return fir + sec;
}
Press + to interact
// sumMain.cpp
#include <templateSum.h>
int main() {
sum(1, 1.5);
}
...