jeudi 7 octobre 2021

Does header only code in C++ lead to faster runtimes despite longer compilation times?

If someone has a choice between keeping his C++ code in header files only (i.e., the full class implementation is in .h files) vs splitting the classes in .h and .cpp files (where .cpp files have the implementation and .h to have the declarations) what are the advantages and disadvantages of each approach? Splitting into .h and .cpp files will obviously lead to faster compilation times. However if you keep your code only in .h files it seems to me that this may give more opportunities to the compiler to better optimize the code. Does a header-only implementation typically lead to faster code?

Aucun commentaire:

Enregistrer un commentaire