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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:54:55+00:00 2026-05-31T10:54:55+00:00

this sounds weird, but maybe there is exist one… i googled for it, but

  • 0

this sounds weird, but maybe there is exist one… i googled for it, but didn’t find anything.
simple example:
i have one file class1.h:

#include "a.h"
#include "b.h"

another file class2.h:

#include "a.h"
#include "c.h"

and main.cpp:

#include "class2.h" //as we see here, we getting "a.h" double included by class1.h and class2.h

i want to get rid of such dupes in my project.

sure, in example it not that hard, but i have huge amount of files which includes each other in many ways and hard to trace all dupes by myself.

any suggestions, before i going to code that tool by myself? 🙂

  • 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-31T10:54:57+00:00Added an answer on May 31, 2026 at 10:54 am

    As i see it, if the code in a file relies on other stuff to be declared, it should include the file that contains those declarations. Otherwise, stuff gets brittle and includes have to be done all the time and in a certain order, and it all gets ugly. So to me, the “duplicate includes” are a good thing; each piece of the code can take care of its own dependencies with less hassle.

    As for how to keep things from breaking on duplicate includes…there’s an idiom called “include guards”. They look a little something like this…

    (file1.h)

    #ifndef FILE1_H
    #define FILE1_H
    
    (the meat of file1.h goes in here)
    
    #endif
    

    When this file is included the first time, FILE1_H isn’t defined yet (or shouldn’t be, assuming you pick better names for your files than this), so the code gets included (and FILE1_H subsequently gets defined). The next time it’s included, though, FILE1_H is now defined, so the code gets skipped.

    (By the way, any macro name will work for this, as long as it’s unique per file. But that particular constraint is the biggest reason the macro’s name is almost always based on the file name.)

    On most compilers, #pragma once works as well. But it’s not standard; if you care about being able to use any compiler you want, then don’t use it (or use it in addition to the include guard).

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

Sidebar

Related Questions

I know this sounds weird, but apparently one of my columns is locked. select
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
This sounds like a look-up-in-the-manual question to me, but I can't find it. Suppose
This sounds like a really simple question, but I am new to PHP. If
This sounds simple but my regex knowledge is limited. I need an expression to
I know this question sounds weird, but please, let me explain myself. I'm using
This sounds like a weird title and probably not stated too well. But here's
This may sound weird but ive been banging my head for the past 2
Ok I know this is going to sound weird but it is what the
This sounds dumb, but I can't get it to work. I think i just

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.