Jump to content
  • Advertisement
Sign in to follow this  
Carradine

Cyclic Dependency solving without Forward Declaration

This topic is 4668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!