Cyclic Dependency solving without Forward Declaration

Started by
6 comments, last by SiCrane 18 years, 3 months ago
I am currently working on code which uses other programs to generate .h header files, I am attempting to duplicate this process that the program uses. One header file that has already been created has a cyclic depenency ( one class uses another class within the same header file ). However the header file does not use forward declaration, yet it compiles fine. Also, I never found any class declaration anywhere within the entire project. When I basically attempted to create a copy of this code, I get the "class not defined" errors because the class is declared after the class that access it. I am not allowed to modify the header files in any way. I have been doing alot of research and I find 99% of all issues like this can be solved using forward declaration. However I believe I am in need of the 1% solution. Any help would be appreciated. Carradine

--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com

Advertisement
Uhhhhhhh... so you want to refer to a class without first declaring it? Seems unlikely. I'm guessing the forward declarations are there; you just can't find them. (keep in mind that they might be in a different header)
Post the class definitions.
class UAnimNode : public UObject
{
...
virtual void GetAnimSeqNodes(TArray<UAnimNodeSequence*>& Nodes);
...
};

//Further down the file

class UAnimNodeSequence : public UAnimNode
{

};


I do a complete search for "class UAnimNodeSequence" throughout the entire project, and there is nothing, and this file compiles

--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com

And yet that doesn't compile, on any compiler that I've ever heard of.

There's more going on there than you realize. Preprocessor tricks, perhaps, or perhaps files that aren't in the project are being #included. What you've posted there, by itself, does not work.
I have to assume there are preprocessor tricks going on. There are #defines within the project and I assume I need to really pull these macros apart to see if anything really is constructing a forward declaration.

But to be sure, is using a forward declaration pretty much the only way to solve a cyclic dependancy?

--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com

Yep.

Programmer trick for unravelling preprocessor tricks: your compiler will, if you tell it to, output a preprocessed version of a source file, with all #includes included and all #defines defined. This will be an ugly monstrosity which you can grep through for clues.
If there's template trickery involved then the template code may refer to types not yet declared so long as the types are declared at the point to template instantiation.

This topic is closed to new replies.

Advertisement