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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:15:34+00:00 2026-05-16T18:15:34+00:00

How do you solve created by including a header file with the same name

  • 0

How do you solve created by including a header file with the same name as another header file already indirectly included as a result of another include?

For instance:

// src/blah/a.hpp
#ifndef A_HPP
#define A_HPP

namspace blah
{

class A
{
}

}

#endif

// src/blah/b.hpp
#ifndef B_HPP
#define B_HPP

#includes "a.hpp"

namspace blah
{

class B
{
}

}

#endif

// src/foo/a.hpp
#ifndef A_HPP
#define A_HPP

namspace foo
{

class A
{
}

}

#endif

// src/foo/c.hpp
#ifndef C_HPP
#define C_HPP

#includes "../b.hpp"
#includes "a.hpp"       // won't be included due to multiple inclusion prevention

namspace foo
{

class C
{
}

}

#endif

In the last header file, a.hpp won’t be included because of the multiple inclusion preprocessor guards. Really, this should be okay though since the classes are in different namespaces. I realize that the easy way is to just change the name of foo/a.hpp or to just give it a fake name in the multiple inclusion guard. Is there a better way?

EDIT
I understand that you can solve this problem by using a more descriptive name in the #define and #ifndef directives (e.g. FOO_A_HPP and BLAH_A_HPP), but I want to know if that is the recommended or best way. Would some people recommend using a different file name as a better solution or does it not really matter? Would you recommend using the convention:

<NAMESPACE>_<CLASS>_HPP

instead of

<CLASS>_HPP

to give a better chance of avoiding these problems in general?

  • 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-16T18:15:34+00:00Added an answer on May 16, 2026 at 6:15 pm

    You solve this, simply, by not using the same #define at the top …

    It would be better to use BLAH_A_HPP and FOO_A_HPP etc so that the #define also includes the namespace name.

    Edit: Well personally I recommend doing the following:

    1) Don’t name headers the same (ie use different file name … this doesn’t always help) and use different #define names..
    2) Don’t name classes the same thing. Put 1 class per header and name the header after the class
    3) If they are differentiated by a namespace use that namespace in the file name AND #define
    4) Add an ID to you #define that is unique to you (I could use GOZ for example)
    5) Make use of #pragma once. Its useful for the compilers that ise it.

    Its all a matter of taste though. Choose a scheme that works for you and stick with it. There is no right or wrong. As long as it works and is consistent.

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

Sidebar

Ask A Question

Stats

  • Questions 533k
  • Answers 533k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer EF is not overkill for web apps. I disagree with… May 17, 2026 at 12:37 am
  • Editorial Team
    Editorial Team added an answer You can test and set a flag once you call… May 17, 2026 at 12:37 am
  • Editorial Team
    Editorial Team added an answer You are running the code too early. You should wrap… May 17, 2026 at 12:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Please help me solve my big problem. in my on-line shopping project i created
@Solved The two subquestions I have created have been solved (yay for splitting this
I'm trying to figure out how to solve the privilege acquisition. The application requires
I've just started working with Visual Studio and C#, and am trying to solve
Hi I created my first web service. It work fine but now I need
I created two buttons named supportweb and email , and under these buttons I
I created a javascript AdoNetDataContext and created a DataView from it. I was using
I have created this little program to calculate pi using probability and ratios. In
Where I work, we have a large codebase of C code that we build
I have such task - to create control that union two controls (DataGrid from

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.