Assume these two cc files:
0.cc
#include <iostream>
template <class T>
T test(){
 return 5;
}
int main(){
 return test<int>();
}
1.cc
template <class T>
T test(){
 return 5;
}
We compile them with g++ 0.cc 1.cc.
This compiles and runs successfully but if above functions were not templates then we would get a duplicate symbol error during compilation and linking phase.
Why using templates does not generate a link error?
 
    