c++ – How does the compiler/linker manage without object files for template classes?


Actually in this question, obscenely simple, but in Google did not find the answer. Compiling in qtcreator, I noticed that there are no corresponding .o files for template classes. Okay, it's clear that there is no corresponding .cpp, but in theory, a template class, when used, dynamically generates a "normal" class with the corresponding type parameters, right? And how do the functions of this class "get" into the executable file without the mediation of the object ones? Directly? If object files are so unneeded, then what are they even for?


  1. object files are generated not for classes, but for translation units;
  2. the body of instantiated templates is placed in the translation unit that instantiates them;
  3. no one forces you to explicitly create and use object files, most compilers allow you to immediately build an executable file
Scroll to Top