Declaration is just stuff that says 'something exists, but somewhere else'. Function prototypes are declarations.
Rewriting main.cpp without any chapter_1_3.hpp:
1 2 3 4 5 6 7 8 9
int read_Number();
int writeAnswer(int SumNum);
int main()
{
int sum = (read_Number()) + (read_Number());
writeAnswer(sum);
return 0;
}
<-- These are a prototypes for functions that exists elsewhere (in this case, in "chapter_1_3.cpp")
<-- 'Prototypes' tell the compiler what something looks like: return type, name, arguments, etc.
However, this means that "main.cpp" must know a lot about what is in "chapter_1_3.cpp".
So we tend to keep things as separate as possible: every .cpp has its own .hpp:
- chapter_1_3.hpp tells me what is in chapter_1_3.cpp
- chapter_1_3.cpp has stuff in it
Now the code that uses chapter_1_3's stuff only needs to include "chapter_1_3.hpp" to know all it needs to know about chapter_1_3.cpp. The additional benefit is that if main.cpp has something incorrect in it about chapter_1_3.cpp then the compiler will tell you all about it (in detail), and you can fix main.cpp to match what chapter_1_3 actually has.
Thank you for the reply. I worked a lot with multiple file inclusion and got to understand how to add a .cpp file to another.cpp file. Cool. Thanks for pointing me in the right direction.