Including a .h that also includes current .h
Is it not possible to include an .h that also includes that .h?
AFile.h includes BFile.h but BFile.h also includes AFile.h It is possible to have a UPROPERTY of type UAFile in AFile.h though...
Will I just have to work around this limitation?
asked Sep 14 '18 at 06:24 AM in C++ Programming
You can forward declare your classes, I'd look up a tutorial somewhere but here's the basics:
You can't include the .h files in each other, since that will cause a loop
You can however include them in the .cpp files.
Provided you don't need to interact with the classes from the other .h in your .h, you just need to create the variables, you can instead declare a class with the same name so the first class knows it exists
This way you can setup variables in your header as normal then make use of them by including the other header in your .cpp
answered Sep 14 '18 at 09:57 AM
What you're doing is called a circular dependency and won't work. To compile the first class the compiler will need to know about the second which in turn needs to know about the first... As Harry mentioned you can used forward declaration, but to do this you need have only either pointers or reference to the other class, otherwise it won't change anything.
That's a complex issue which is usually a design issue, you should try to organize your classes dependencies differently. This thread on stack overflow explains all the ways to solve your issue, hope that helps!
answered Sep 14 '18 at 03:58 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here