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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:08:32+00:00 2026-05-18T00:08:32+00:00

Say I’m making a project and I have most the project in a namespace

  • 0

Say I’m making a project and I have most the project in a namespace named Project. I define a class inside the namespace Project named MainProject.

In the source file, to implement the class, do I do ‘using namespace Project;’ or do I wrap it in a ‘namespace Project { … }’ nest?

  • 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-18T00:08:33+00:00Added an answer on May 18, 2026 at 12:08 am

    Given a header “n.h”:

    namespace n{
      extern void f();
    }
    

    The following does not define f() in namespace n (from here on, I’ll refer to it as n::f:

    #include "n.h"
    using namespace n;
    
    void f(){ }
    

    If you try to refer to n::f anywhere, you’ll get a link-time error. The above defines an f in the global namespace. This does define n::f:

    #include "n.h"
    void n::f(){ }
    

    This also does:

    #include "n.h"
    namespace n{
      void f(){ }
    }
    

    but has a downside where if you mis-type the name or signature, you’ll add a new function to the namespace and leave void n::f() undefined, leading to a semi-annoying link-time error.

    When classes are involved, things are a little different:

    namespace n{
      class c{
        void f();
      };
      extern c operator + (const c&, const c&); // I'll use Matthieu M.'s example
    }
    

    This will be okay, because there is no global c:

    #include "n.h"
    using namespace n;
    void c::f(){ }
    

    But the following will cause a link-time error if you try to add two c’s, for the same reason as with the first attempt at defining n::f():

    #include "n.h"
    using namespace n;
    c operator + (const c &a, const c &b){ /* blah blah */ } // define global +
    

    This scenario will also cause a link-time error (or maybe even a compilation error, depending on where ::c::f is defined):

    class c{ // a global c, defined in some header somewhere
      void f();
    };
    
    #include "n.h"
    using namespace n;
    void c::f(){ } // define the global c::f (a possible redefinition) and n::c::f remains undefined!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a bash script file config.sh . It's meant to be source'd
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
Say I have a class named Frog, it looks like: public class Frog {
Say I have the following generic class: public class Foo<T extends Bar> { //
Say I want to create a card class. and want to have enums for
Say i have this old manuscript ..What am trying to do is making the
Say that I have a singleton class (Downloader) responsible for downloading and persisting files.
Say I have a class pet and it is composed of two variables: Class
Say I have a container with various elements inside. In turn, any element could
Say I have the following template function: template <class T> void apply(const vector<complex<T> >&

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.