C++ question
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??
Quote:Original post by jdubHeaders 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.
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??
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).
Quote:Original post by jdub
I have heard that headers shouldn't #include other headers.
You shouldn't include unnecessary headers. Some are necessary.
Quote:Original post by jdubHeaders (and source files) usually have to include headers.
I have heard that headers shouldn't #include other headers.
However, no files should include source files (.cpp).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement