Seeing you define an "interface" file as what is typically called a "header" file makes this finally clear for me. The word header never made sense to me. Thank you.
Thank you, Mike, for creating these insightful videos. I have a suggestion for future content: it would be incredibly helpful if you could produce a series of videos on build automation for C++ projects, covering topics such as Makefile, CMake, and Conanfile, from beginner to advanced levels. Your guidance on this subject would be greatly appreciated.
Good stuff! Most of my work is writing Java code, but I'm interested in C++. I found a "bad" tutorial online that uses implementation code in the hpp files, so I had questions about the authors code. Very clear explanation. Thanks!
Thank you so much Mike! I have questions regarding class templates separation. Are there other ways to implement class templates separately from declarations, except including one header to another? And how can we improve compiling time of multiple complex templates? Are compilers able not to regenerate classes from templates, which were generated previously?
Cheers! There are some tricks for precompiling headers that can improve compile times. Part of the reason for separating files is to avoid compilation in some cases, though once you have a single #include, then everything gets rebuilt which takes a bunch of time. There's been a few cppcon talks on this, and it's a topic I will eventually visit on this series as well :) Hopefully most compilers will also start supporting modules to further improve compile times with templates.
curious why the different nomenclature of file extensions exists like the H, HXX or HPP etc. If they all serve same purpose, then why multiple types exists? Assume, there are different type of interface or header files?
@@shkhamd .h historically for C header files, then .hpp historically for C++ headers. It actually doesn't matter (some use .inc as well). The extension otherwise might indicate something about the build/contents of header file within a team
What if you don't use header files and always include the .cpp file directly? If your using an open source code base and don't care who can see the implementation wouldn't it be simpler to just have 1 file per class rather than 2?
#include is a no no, as .cpp files are meant to be compiled. While it is true that folks like to distribute .h and .hpp as 'header only libraries' (e.g. stb_image), that can slow down compilation quite a bit. In the case of folks who distribute .hpp files, they don't care to protect the implementation which is fine. Best practice however still dictates to split up the files into separate .cpp and .hpp files, it helps build systems compile code faster, and can help make it easier to trace bugs when we have line numbers and explicit files that contain implementation (because who knows where the .hpp actually gets placed).
you actually explained this perfectly unlike code academy and other online forums.
Cheers, thank you for the kind words! 🙂
Seeing you define an "interface" file as what is typically called a "header" file makes this finally clear for me. The word header never made sense to me. Thank you.
Agreed, that helped me as well. I think other languages got this write with 'interface' keywords 🙂
Thank you, Mike, for creating these insightful videos. I have a suggestion for future content: it would be incredibly helpful if you could produce a series of videos on build automation for C++ projects, covering topics such as Makefile, CMake, and Conanfile, from beginner to advanced levels. Your guidance on this subject would be greatly appreciated.
Cheers -- thank you Mohammad! That's at the top of the wishlist, it will come to this channel :)
Great timing! I was just wondering this to myself last night
⌚ wonderful!
Clear and easy to digest. Thank you!
Cheers!
Good stuff! Most of my work is writing Java code, but I'm interested in C++.
I found a "bad" tutorial online that uses implementation code in the hpp files, so I had questions about the authors code.
Very clear explanation. Thanks!
Cheers! Welcome to C++ 🙂
Very wonderfully explained as always. Thank you.
Cheers you are most welcome!
I love your videos sir how you explain its very easy to understand I love your teaching method.
Cheers, thank you for the kind words!
thank you for this masterpiece of an explanation
Cheers!
Thank you so much Mike! I have questions regarding class templates separation. Are there other ways to implement class templates separately from declarations, except including one header to another? And how can we improve compiling time of multiple complex templates? Are compilers able not to regenerate classes from templates, which were generated previously?
Cheers! There are some tricks for precompiling headers that can improve compile times. Part of the reason for separating files is to avoid compilation in some cases, though once you have a single #include, then everything gets rebuilt which takes a bunch of time. There's been a few cppcon talks on this, and it's a topic I will eventually visit on this series as well :) Hopefully most compilers will also start supporting modules to further improve compile times with templates.
@@MikeShah Awsome! I will watch this with pleasure, looking forward :)
Thanks Mike!
Cheers!
Thank again Jordan Belfort for another entertaining and informing video about modern C++
Hey Mike - why do you prefer guards to #pragma once?
Most all compilers should have pragma once. The preference I think is more so historical, and I know every compiler will work with header guards
I also wanted to ask this :)
curious why the different nomenclature of file extensions exists like the H, HXX or HPP etc. If they all serve same purpose, then why multiple types exists?
Assume, there are different type of interface or header files?
@@shkhamd .h historically for C header files, then .hpp historically for C++ headers. It actually doesn't matter (some use .inc as well). The extension otherwise might indicate something about the build/contents of header file within a team
What if you don't use header files and always include the .cpp file directly? If your using an open source code base and don't care who can see the implementation wouldn't it be simpler to just have 1 file per class rather than 2?
#include is a no no, as .cpp files are meant to be compiled. While it is true that folks like to distribute .h and .hpp as 'header only libraries' (e.g. stb_image), that can slow down compilation quite a bit. In the case of folks who distribute .hpp files, they don't care to protect the implementation which is fine. Best practice however still dictates to split up the files into separate .cpp and .hpp files, it helps build systems compile code faster, and can help make it easier to trace bugs when we have line numbers and explicit files that contain implementation (because who knows where the .hpp actually gets placed).
I liked the "these things exist" comment
Cheers! Everything has a reason!