Sign in to follow this  
jdub

C++ question

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this