Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:25:40+00:00 2026-06-09T10:25:40+00:00

Possible Duplicate: What is the purpose of forward declaration? Forward Declaration vs Include i

  • 0

Possible Duplicate:
What is the purpose of forward declaration?
Forward Declaration vs Include

i am a bit confused with the #include *.h file inclusion in both the header and cpp files. I see that some .h files are included in the header file and some in the corresponding cpp file. I would guess that all needed .h files would need to be included in the header file and thus do not see a reason why they have been included in the cpp file. Is there any specific reason for this?

Also, I see that some needed classes have been included in the header file using Class ClassName;. How is this different from just including the ClassName.h in the header file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:25:42+00:00Added an answer on June 9, 2026 at 10:25 am

    In your first paragraph you seem to say that the same .h file is included in the class’ header file and the class’ .cpp file? That’s just an oversight since including a file that includes other files, by definition, also includes those other files. You can remove the duplicate include in the .cpp file.

    In your second paragraph, what you are seeing is a forward declaration of a class. If you don’t need a class’ definition in the header than sometimes it’s good practice to just forward declare it. This way, files that include the header aren’t dependent on the class’s definition. This cuts down on dependencies between files. An example of only needing a forward declaration is if a class contains a member variable that’s a pointer to a class as opposed to the class itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: In C++ why have header files and cpp files? I don't quite
Possible Duplicate: What is an MDF file What is the purpose of the mdf
Possible Duplicate: What is the purpose of wrapping whole Javascript files in anonymous functions
Possible Duplicate: What is the purpose of wrapping whole Javascript files in anonymous functions
Possible Duplicate: What is the purpose of wrapping whole Javascript files in anonymous functions
Possible Duplicate: What is the purpose of wrapping whole Javascript files in anonymous functions
Possible Duplicate: What is the purpose of a self executing function in javascript? Please,
Possible Duplicate: What is the purpose of the Assemblies node in Web.Config? I removed
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? I've
Possible Duplicate: What is the purpose of a marker interface? Is it bad practice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.