Common Header file like "JuceHeader.h" and forward declarations

I’m looking at including a lot of classes into a common header file similar to the “JuceHeader.h” so I can avoid a jumbled include mess by just adding one single header file with everything in it.

One thing I notice with the JuceHeader.h is that all the classes are first forward declared and after the associated class headers are included.

My question is around why you would do this. Is it that if you have a class that includes “JuceHeader.h” and the compiler finds that the forward declaration of some class you use is enough to compile, it then ignores the associated included header file? Basically, by forward declaring first you are using this as a first try and if that is not enough it then parses the entire header?

Just to answer my own question…

1 Like