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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:35:12+00:00 2026-05-16T20:35:12+00:00

If one has a header file, let’s say test.h including namespace test { enum

  • 0

If one has a header file, let’s say “test.h” including

namespace test
{
   enum ids
   {
      a = 1,
      b = 2,
      c = 3,
      d = 30
   };

   char *names[50];
};

and a source file, “test.cc” basically only including

test::names[test::a] = "yum yum";
test::names[test::c] = "pum pum";
// ...

Wouldn’t it make more sense to wrap the implementation inside the namespace, too?

I’d say it would, as it’s after all the implementation of the header file, so it would make sense to include the implementation in the same namespace as the header without manually prefixing every variable with test::, and prefix when using values from the outside.

This is the opinion of a C++ rookie, what would the smarter people say here?

  • 1 1 Answer
  • 1 View
  • 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-16T20:35:13+00:00Added an answer on May 16, 2026 at 8:35 pm

    You can specify the namespace in test.cc as well. To do this, you would do something like:

    #include "test.h"
    
    namespace test
    {
        ...
        names[a] = "yum yum"; 
        names[c] = "pum pum"; 
        ...
    }
    

    You could alternately use using as in:

    #include "test.h"
    
    using test;
    
    ...
    names[a] = "yum yum"; 
    names[c] = "pum pum"; 
    ...
    

    I generally use the first method.

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

Sidebar

Related Questions

I have Visual studio 2005 . One of my header file has a enum
I have one class, called A, and it has it's own header file. Then
Is there a general term for a pairing of tables where one has header
I have an excel sheet that has several headers. One of the header is
I have one map within one header file class: class One { // code
I have a header file called stdafx.h and this one is precompiled of course.
I have an application that has an included header file in each page. The
One has txtDateReceived and second has txtVendorPackDate. Before insert will add record I have
This one has me pretty rattled so I thank you in advance for your
This one has been stumping me for a while. But I'm no expert. This

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.