Jump to content
  • Advertisement

Archived

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

CobraMantis

"#include" trouble

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

Here''s a silly question. I''ve got two header files for two different classes, class A and class B. Both objects have pointers to types of the other class as private members. Here''s where my problem comes in...each class has to know about the other one. In the preprocessor directives for the header file "A.h" I have ''#include "B.h"''. For the "B.h" header file, I can''t have ''#include "A.h"'', or it would endlessly include each file over and over. What can be done to get around this? I hope I explained it clearly enough to understand my problem...if not just let me know. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You make sure that each header file is only included once:

#ifndef FILE_NAME_OR_WHATEVER    // if it hasn't been included
#define FILE_NAME_OR_WHATEVER    // use this to show it's been included

class A
{
...
};

#endif

Note: The capitals are merely a naming convention, and are not mandatory.

If I have understood you correctly, you are also probably going to have to use a forward declaration. Have a look on Google to find out what I'm talking about.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on July 26, 2003 6:50:26 PM]

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!