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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:47:27+00:00 2026-05-26T19:47:27+00:00

I have 3 classes (it could be 300) , each one with its own

  • 0

I have 3 classes (it could be 300) , each one with its own header and implementation.
I’d like to write an ‘elegant’ way to organize the way I load of any class needed by every class of the three. Maybe this example helps…

I have : class1 class2 class3

Every header has:

#ifndef CLASS#_H 
#define CLASS#_H   
  #define FORWARD_STYLE
  #include "general.h"
 #endif

Every implementation has:

  #define DIRECT_STYLE
  #include "general.h"

OK
I’m going to write a ‘general.h’ file in which I’d have :

#ifndef DIRECT_STYLE 
#ifndef CLASS1_H
#include "class1.h"
#endif
#ifndef CLASS2_H
#include "class2.h"
#endif
#ifndef CLASS3_H
#include "class3.h"
#endif
#endif

#ifndef FORWARD_STYLE 
class Class1;
class Class2;
class Class3;
#endif

// a lot of other elements needed 
#include <string.h>
#include <stdio.h"
....
#include <vector.h" 
( all the class I need now and in the future )

This is a good structure ? Or I’m doing some idiot thing ?
My goal is having one unique ‘general.h’ file to write all the elemenst I need…
Are this to work fine ?
Thanks

  • 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-05-26T19:47:27+00:00Added an answer on May 26, 2026 at 7:47 pm

    The basic rules to follow are:

    1. Let each of your source file include all the header files it needs for getting compiled in a standalone manner. Avoid letting the header files include in the source file indirectly through other files.
    2. If you have constructs which will be needed across most source files then put them in a common header and include the header in Only in those source files which need it.
    3. Use Forward declarations wherever you can.There are several restrictions of when you can get away using them,read this to know more about those scenarios.

    Overall it is a good idea to avoid including unnecessary code in source files through a common header because it just results in code bloat, so try and keep it to a minimum. Including a header just actually copy pastes the entire header to your source file and Including unnecessary files has several disadvantages, namely:

    1. Increase in compilation time
    2. Pollution of global namespace.
    3. Potential clash of preprocessor names.
    4. Increase in Binary size(in some cases though not always)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, Car and Person. Car has as one of its members
I have a lot of classes in the App_Code directory could this be a
I have classes which have automatic properties only like public customerName {get; set;}. They
If I have classes A, B, C, D, E , and interfaces like X,
I have some classes layed out like this class A { public virtual void
I have a bunch of classes extending an abstract Base class. Each subclass takes
I have classes like the following. That is many classes with the same few
I have classes that are structured like the following: public class Forecast { [Key]
I have few own APIs with around 2000 classes overall. Some of them use
I have created my own Tree implementation for various reasons and have come up

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.