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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:48:28+00:00 2026-06-06T08:48:28+00:00

I am not certain about this and searching a bit hasn’t turned up anything

  • 0

I am not certain about this and searching a bit hasn’t turned up anything specifically useful. So, supposing I have a header file with a namespace that contains some classes C1 and C2;

namespace my_namesp {

class C1 {
public:
  blah1;
  ...
private:
  blah2;
...
};

class C2 {
public:
  junk1;
  ...
private:
  junk2;
  ...
};

} //-End namespace

Now supposing in the implementation (CPP), I have all the member functions of C1, C2 defined, then supposing I have some common data that I want C1 and C2 to share, say, an enum and a string array, but I don’t necessarily want them to be a part of either class. Then is it legal to do the following (note: it builds and works fine); and how about if I am exporting this implementation as a library for a client application? Would this still work? Is this kind of a design frowned upon, for any reason that I should be aware of? Perhaps a specific feature of OOP might be better suited for this kind of thing?

namespace my_namesp {

enum some_list_num {
   list_member1,
   list_member2,
   ...,
   list_length
}

static const std::string string_list[] = {
   str1,
   str2,
   ...,
   strN 
}

return_type C1::some_func1(...) {
   ...
}

...

return_type C1::some_func1(...) {
   ...
}

} //-End my namespace

Thanks in advance again for any ideas/corrections.

  • 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-06-06T08:48:30+00:00Added an answer on June 6, 2026 at 8:48 am

    If C1 and C2 share some implementation details which should be kept local to the translation unit, that’s fine.

    It is better to put them in an anonymous namespace in the cpp file, so there is no risk of linker symbol clashes later (ie, in case a library client rashly adds something to your namespace and accidentally reuses one of your “private” names).

    The cpp file might look like:

    namespace { // private implementation details
    
        enum some_list_num {
           list_member1,
           list_member1,
           ...,
           list_length
        }
    
        static const std::string string_list[] = {
           str1,
           str2,
           ...,
           strN 
        }
    
    }
    
    namespace my_namesp { // define externally-visible functions etc.
    
        return_type C1::some_func1(...) {
           ...
        }
    
        return_type C1::some_func1(...) {
           ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: After searching a bit I don't seem to be alone about this problem:
I'm not certain how to explain this with the correct terms so maybe an
I have certain PHP class methods that access external variables. These variables are not
We have a program with a main() that parses certain CLPs but does not
I know this sort of code is not best practice, but nevertheless in certain
I am doing a project for a certain bank. They do not have a
I've a doubt about this question, not relatively to a specific language: when I
I apologize if this has already been asked - I'm not certain of the
I am trying to learn about searching for certain keywords for a project I
I am having an issue with implicit conversions not working under certain circumstances (higher

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.