I had initially inquired about why .h files are necessary for C++. I had a question regarding why not just do #include /file.cpp instead (where file.cpp would contain function/class declarations and definitions), but then I found this link which stated that doing this would surmount to essentially copying all code from the file.cpp. So if I'm understanding this right:
- The confusion/error comes from linking. So if I just compiled the main file
#include /file.cpp, but not the actualfile.cppitself, wouldn't I prevent this error from occuring? Or is it such that you automatically compile AND link anything that you#include? - If it is possible, then is the reason why we don't do this because in large projects, it is easier to compile a
.hfile that has been listed to#includeinstead of a.cppfile, even though the contents of the.cppfile will be called many times (ie. the.cppfile only has to be compiled once)?