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 7886453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:19:19+00:00 2026-06-03T05:19:19+00:00

If I have a piece of code, say main.cpp that requires the classes defined

  • 0

If I have a piece of code, say main.cpp that requires the classes defined in myheader.h is it bad practise to then include all the libraries/headers required for main.cpp in the myheader.h file?

If so, why? Considering that main.cpp won’t work without myheader.h any way.

Sorry if this question is a little simple – I’m just unsure of the common practise with separating across multiple files.

  • 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-03T05:19:21+00:00Added an answer on June 3, 2026 at 5:19 am

    In general, you should include only those things that are needed in the current file. OK, so main.cpp uses myheader.h anyway, so why not include, say, <iostream> and other headers in myheader.h which are needed by main.cpp? Because tomorrow you will want to include myheader.h into myOthercpp.cpp which doesn’t need <iostream> or other headers included in myheader.h, which is redundant and increases compilation time. So, whatever is needed in main.cpp, include in main.cpp.

    There is an exception to this pattern which is called precompiled headers.

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

Sidebar

Related Questions

Let's say I have to implement a piece of T-SQL code that must return
Let's say I have a piece of code that runs fine on an OS.
I have this piece of code: while(fileStream>>help) { MyVector.push_back(help); } ...and lets say that
I have a piece of code here that i really could use some help
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
Let's say we have the following piece of code: public class Event { }
Say we have a piece of code: //... class A //... A* myA =
Lets say i have a piece of code like this: test pattern | pattern
Let's say I have the following piece of code. server = TCPServer.new(3200) client =
I have piece of code: class example { public function say($x) { if ($x

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.