Quote:
Originally Posted by
kristinu
In most of my classes I have both a .h and a .cpp, with some inline functions in the .h file as well. One reason I was thinking of keeping the .cpp and corresponding .h files together in same directory. For templates, the declaration and implementation are all in one file as usual.
I've already spent this entire thread explaining that this is
not "as usual". Please reread.
IF your entire project is two or three files, why bother making folders at all? #include "filename.h" is easy. But when you divide things into multiple folders, #include "filename.h" doesn't work -- they can't find each others' headers, anymore. The code or the compiler needs to be told where to look. Lots of ways to do that:
1)
#include "../library1/filename.h" -- silly.
2)
cc -I ./library1 -I ./library2 -I ./library3 -I ./library4 -I ./library5 -I ./library6 -- I bet you can see the problem with this too.
4) Create symlinks in each and every individual folder so #include "filename.h" succeeds -- a silly amount of work.
3)
cc -I ./include -- the way it's supposed to work.
Header files are
supposed to be grouped separately from the source. They're supposed to be separate enough that, once you compile the .cpp file, you can tar up and ship the .o or .so with the .h file and forget the .cpp. That's why they exist -- to declare what symbols are
available in an object or library without defining the object's entire contents.