I am wondering why C++ compilers don’t generate header guards automatically for headers?
// Why do I have to write this for every .hpp file I create?!!
#ifndef myheader_hpp__
#define myheader_hpp__
// ...
#endif
I haven’t met a situation where they aren’t needed when I write my headers. I can’t see a real use-case of the opposite behavior, but I would be glad to see one. Is there a technical difficulty or is it just history?!
There are some preprocessor tricks that require the same header included multiple times into the same compilation unit. Another reference.
Besides that, most compilers do allow you to shorten all of that down to: