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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:48:41+00:00 2026-05-15T10:48:41+00:00

I’m currently in the process of developing a fairly large static library which will

  • 0

I’m currently in the process of developing a fairly large static library which will be used by some tools when it’s finished. Now since this project is somewhat larger than anything i’ve been involved in so far, I realized its time to think of a good structure for the project. Using namespaces is one of those logical steps.

My current approach is to divide the library into parts (which are not standalone, but their purpose calls for such a separation). I have a ‘core’ part which now just holds some very common typedefs and constants (used by many different parts of the library). Other parts are for example some ‘utils’ (hash etc.), file i/o and so on. Each of these parts has its own namespace. I have nearly finished the ‘utils’ part and realized that my approach probably is not the best. The problem (if we want to call it so) is that in the ‘utils’ namespace i need something from the ‘core’ namespace which results in including the core header files and many using directives.

So i began to think that this probably is not a good thing and should be changed somehow. My first idea is to use nested namespaces as to have something like core::utils. Since this will require some heavy refactoring i want to ask here first. What do you think? How would you handle this? Or more generally: How to correctly design a static library in terms of namespaces and code organization? If there are some guidelines or articles about it, please mentoin them too. Thanks.

Note: i’m quite sure that there are more good approaches than just one. Feel free to post your ideas, suggestions etc. Since i’m designing this library i want it to be really good. The goal is to make it as clean and FAST as possible. The only problem is that i will have to integrate a LOT of existing code and refactor it, which will really be a painful process (sigh) – thats why good structure is so important)

  • 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-15T10:48:41+00:00Added an answer on May 15, 2026 at 10:48 am

    Well, I would think that in the core.h header, you would have stuff like

    #include <string>
    #include <iostream>
    namespace core
    {
        typedef std::string mystring;
        #define mycout std::cout
    }
    

    And not one using directive, to prevent contaminating the global namespace. In a utils.h header, you would use stuff like:

    #include "core.h"
    namespace utils
    {
        core::mystring stringfunction(core::mystring &stuff)
        {
            core::mystring result;
            // do stuff
            return result;
        }
    }
    

    Hence, there is no mystring anywhere, except in core::. It involves a bit more typing, but that’s what namespaces are for, letting yourself know where you’re getting the type/function/class from.

    UPDATE

    The other side of the story is something like this:

    core.h header declaring stuff in core namespace like above.

    utils.h header declaring stuff in core::utils namespace, and after that a namespace utils = core::utils statement. This makes the two approaches identical to the user, and allows you to write stuff like mystring instead of core::mystring in the utils*.h headers and *.cpp files.

    Something like this for a utils.h:

    #include "core.h"
    namespace core
    {
        namespace utils
        {
            mystring stringfunction(mystring &stuff)
            {
                mystring result;
                // do stuff
                return result;
            }
        }
    }
    namespace utils = core::utils; // allow user to type utils::stringfunction
    

    This cleans up user- and library code a bit.

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

Sidebar

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.