I've seen code that uses forward headers that are #include'd where otherwise there would be forward declarations. By "forward header" I mean a header that includes only forward declarations. So you might have class.cpp, class.h, and class_fwd.h or just class.h and class_fwd.h if class.h contains templates.
Examples of this are in Boost, which has somefile_fwd.hpp files.
When is creating and including a forward header preferable to explicit forward declarations? When is it not? What are the advantages and disadvantages of this practice? Should one create a forward header for all headers?
This question is essentially the same:
Forward declaration include, on top of declaration include (ClassFwd.h + Class.h)
Why I don't find the answers in that question satisfactory:
- Daniel Lidström's answer describes something related that he does but does not address the question specifically.
- Sebastian's answer mostly explains why forward declarations are used in general and then comments on a pattern similar to what Daniel Lidström describes.
- Dialecticus's answer is vague but does hint at templates being a reason to use forward headers.
- Cheers and hth. - Alf's answer is similar to Dialecticus's answer.