I firstly think c++ compiler like g++ generates different functions or classes for different templates in compiling stage, But when we use a lib, lib binary has been made, it has been a fixed binary, just for link, why template still works?
Asked
Active
Viewed 36 times
0
-
Unless the templates are fully defined in the header files it wont work – Alan Birtles Jun 20 '20 at 07:05
-
1Please read a good [C++ programming book](https://stroustrup.com/programming.html) and the [C++11 standard](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf). Read also the documentation of your compiler, perhaps [GCC](http://gcc.gnu.org/) and [this draft](http://starynkevitch.net/Basile/bismon-chariot-doc.pdf) report – Basile Starynkevitch Jun 20 '20 at 07:09
1 Answers
3
When you use a library, you #include
its header files. The logic for a templated function/class is in the header file. This allows the compiler to generate the concrete implementations.

takeshibaconsuzuki
- 67
- 1
- 8