How to stop cyclic references with separate cpp/hpp files


A question primarily for Jules:

Since the JUCE framework is delivered as separate HPP , CPP files i.e. one per class, how did you design these so that one doesnt get endless circular dependencies between your header files ?

of course this has to do with my last question.

I need a way of doing this that can be automated, since my C++ source gets generated by a piece of software I wrote which takes source in a different language and spews out C++.

Currently my generated C++ code compiles fine when I spit out separate cpp files for each class but use a single hpp for all classes. But not when i spit out seperate hpp headers too.

I do put a massive list of forward declarations in a master hpp file in both cases, but this doesn’t solve the cyclic header reference issues.


TBH I’ve never really had any difficulties with circular dependencies, and can’t think of any advice to offer…

Perhaps the problem is that your classes have too many interdependencies? Try using smaller, simpler classes, and stick to the “single responsibility” principle.