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

  • Home
  • SEARCH
  • 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 4028572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:14:12+00:00 2026-05-20T11:14:12+00:00

I am using same class name in two namespaces, say A and B. Should

  • 0

I am using same class name in two namespaces, say A and B. Should the include guards be unique while declaring the classes with different namespaces too?

I mean can’t there be two files names AFile.h (in different directories) with same include guards and declaring different namespaces?

 //File 1:

 #ifndef AFILE_H 

 #define AFILE_H

 namespace A { 

   class CAFile {...

   }; 

 };

 #endif

//File 2:

 #ifndef AFILE_H 

 #define AFILE_H

 namespace B { 

   class CAFile {...

   }; 

 };

 #endif
  • 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-20T11:14:12+00:00Added an answer on May 20, 2026 at 11:14 am

    Your guards need to be different if some code (directly or indirectly) needs to see both A::CAFile and B::CAfile.

    The include guards are dealt with by the preprocessor, that has no knowledge at all of classes (let alone namespaces). If both these files are included when processing a c++ file, and they have the same header guards, only one of the declarations will remain in the preprocessed source that the compiler will see.

    Look at things like Boost files, they have some conventions for the header guards (if I remember correctly).

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

Sidebar

Related Questions

Summary: I want to save two classes of the same name and different namespaces
Say, for example, I have many web applications using the same class library compiled
I am using two web projects and both using same Database of MS SQL
Using the same sort command with the same input produces different results on different
I am using the same ViewController for several different views. When instantiating the ViewController
I want to animate two jquery OBJECTS at the same time (using the jquery
I have two same project in which I have two classes under same namespace
My php function is returning an Error. these two function from the same class
Is it legal? class SomeClass { public: static void f(); }; using SomeClass::f; Edit:
multiple webapp running on same tomcat using same jvm. sometime, one webapp that have

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.