Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PopJimmy

c++ circular header problems using forward declaration

This topic is 5393 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

Hi I''m involved in a rather large coding project, and we''ve run in to trouble. We''ve got a circular set of include-files, and some of the utilizes forward declaration of classes. Now, as we try to define an inheritance (class CPX_InheritObject should inherit class CPX_Object), whom CPX_Object has been previously forwardly declared. The compiler outputs an error message saying "base class undefined". Is there any (valid) way to solve this? The compiler I''m using in Visual Studio.NET 2003 and I''m coding in C++.

Share this post


Link to post
Share on other sites
Advertisement
In order to inherit from an class you can''t have only a forward declaration. However there should be no reason that your base class definition should need the full definition of a derived class, so I fail to see why there''s a circular dependency here.

Share this post


Link to post
Share on other sites
Exactly what SiCrane said.

Put declaration of base class into its own header file. Include this header file where you declare the derived class.

Regards,
Jeff

Share this post


Link to post
Share on other sites
i went nuts over this very same problem with my project which probably has at least 50 files to it now. I have gotten over the problem by creating a types.h file that i include in just about every other header file in the project. The types file has

class SomeClass;
class SomeOtherClass;
. . .

declarations for every class that needs a forward declaration. I then include whatever headers are needed for the live code in the .cpp files, and base class headers i just include in the child class header since it will not take a forward declaration. I also include all public enumerations in the types file to keep them all in one place. My compilation is much cleaner now.

Share this post


Link to post
Share on other sites
quote:
Original post by leiavoia
i went nuts over this very same problem with my project which probably has at least 50 files to it now. I have gotten over the problem by creating a types.h file that i include in just about every other header file in the project.

Your compile time must be through the roof Any change to any of the headers will effectively cause a full rebuild...

Share this post


Link to post
Share on other sites
well, no actually. i''m using GNU Make but i do full recompiles every so often to clean house. Weird bugs creep in if i don''t. What''s you''re better idea? Really, i''m open.

Share this post


Link to post
Share on other sites

  • 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!