Jump to content
  • Advertisement
Sign in to follow this  
jdub

C++ question

This topic is 3363 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 want to use a structure from another header as a parameter to a class function. I have heard that headers shouldn't #include other headers. How is my compiler supposed to recognize the structure if I can't include other headers in my include file??

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by jdub
I want to use a structure from another header as a parameter to a class function. I have heard that headers shouldn't #include other headers. How is my compiler supposed to recognize the structure if I can't include other headers in my include file??
Headers are supposed to include other headers; they're just not supposed to do so unnecessarily, or in ways that lead to circular inclusions of other similar problems.

What you're probably looking for is a 'forward declaration'. By forward declaring the struct in question, you can reference it without having to include the associated header.

Here is a good article that addresses this issue (and other related issues).

Share this post


Link to post
Share on other sites
Quote:
Original post by jdub
I have heard that headers shouldn't #include other headers.


You shouldn't include unnecessary headers. Some are necessary.

Share this post


Link to post
Share on other sites
Quote:
Original post by jdub
I have heard that headers shouldn't #include other headers.
Headers (and source files) usually have to include headers.
However, no files should include source files (.cpp).

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!