Can two c++ classes access each other?

So I have two classes that I want to call functions on each other - let’s call them Alpha and Bravo.

In Alpha.h, I have the line #include “Bravo.h” and in Bravo.h, I have the line #include “Alpha.h” so that both classes will recognize each other’s functions.

But, when I try to compile this, I get the warning that “Unreal Header Generation tool has stopped working.”

So is it not possible, in C++, to have two classes interact with each other? Or am I going about this all wrong?

Okay, I “solved” it by shuffling the #include lines between the .cpp and .h files, and eventually it compiled without crashing. I guess I just need to study header files more, I don’t really know what I am doing.

Your problem here is that in including Alpha.h in Brava.h and visa versa, you’ve created a cyclic dependency. In fairness, UHT should probably give you a more sensible error in this case than simply crashing.

These sorts of problems can usually be fixed by forward declaring Alpha and Bravo for the headers that need them. You only need to actually include the headers at the point you come to use the object(s) defined in those header (which is normally inside the *.cpp. It sounds like you have come to this conclusion on your own though, which is good!

As with many of these sorts of issues, Stack Overflow has lots to say on the topic!

Ah, so it’s called “cyclic dependency.” Thanks for giving me the name, I know what to look for now. :smiley: You guys are awesome, as always.

No problem!