Question:
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?
Answer:
- object files are generated not for classes, but for translation units;
- the body of instantiated templates is placed in the translation unit that instantiates them;
- no one forces you to explicitly create and use object files, most compilers allow you to immediately build an executable file