As for the headers in the library, I see two options, and I'm not sure if this choice really matters. Suppose I created a library, called foobar . Please help me choose the most suitable option:
Whether you include it in the very root of the library project, call foobar.h , which includes all the headers in the library, such as "src / some_namespace / SomeClass.h", etc. Then, from outside the library in the file I want to use, something to do with the foobar library is simply #include <foobar.h> .
You don't have a basic include, and instead you only need to include the headers we need in the places where I use them, so I can have a whole bunch of inclusions in the source file. Since I use namespaces, sometimes up to 3, including the headers, seems a bit of a hassle.
I chose option 1 because of how easy it is to implement. OpenGL and many other libraries seem to do this, so this seemed reasonable. However, the C ++ standard library may require me to include multiple headers in any file, why didn't they have only one header file? If this is not my being and an idiot, but they are separate libraries ...
Update:
In addition to the answers, I think it makes sense to provide both options, right? I would be very annoyed if I wanted to use std :: string, but had to include a lot of header files; that would be stupid. On the other hand, I would be annoyed if I had to type a lot of #include lines when I wanted to use most of the library anyway.
Forward Headers:
Thanks to all that I advised about forward headers, it helped me make the jungle header less complicated! :)
source share