Two classes that refer to each other

You can use forward declarations in the header files to get around the circular dependencies as long as you don’t have implementation dependencies in the headers. In Window.h, add this line:

class App;

In App.h, add this line:

class Window;

Add these lines before the class definitions.

Then in the source files, you include the headers for the actual class definitions.

If your class definitions reference members of the other class (for example, in inlines), then they need to be moved to the source file (no longer inline).

Leave a Comment