Single file components


Is it OK to have single file (.h) components only in my app? I’m not going to make dynamic libraries.
What makes me worry is Juce separate classes into cpp and h files. What’s the reason for it?

As far as I understand the compiler will have to rebuild all files using .h-only component if I change something in the method body. It will rebuild only component’s cpp file if I separate it into cpp and h. Am I correct?


I do it like that more and more these days.

In fact a more radical pattern that I’ve been using recently is like this:

[code] #include “juce headers”
#include “othermischeaders.h”

struct FooClasses
    #include "FooClass1.h"
    #include "FooClass2.h"
    #include ...etc..

void someFunction()
    FooClasses::FooClass foo; 


…where those “FooClass.h” files just contain inline classes, with no header guards or includes or anything else. This is particularly handy when you have a bunch of inline classes that all cross-reference each other, because by putting them all inside an outer class rather than a namespace, they automatically see each other without needing to worry about their order. And by splitting each one into a header file, it becomes easy to navigate around them.


Interesting technique, Jules, where’d you pick that up?


I guess I was just writing a bunch of inline classes in a cpp file, and then they all needed to reference each other, so I put them all inside a parent class, and then it all grew too big so I split it up into separate files… Not sure I’d recommend doing this in all cases, but it can be handy sometimes.