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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:22:56+00:00 2026-06-11T16:22:56+00:00

Consider following code – namespace N1 { class A { //some implementation } class

  • 0

Consider following code –

namespace N1
{
    class A
    {
        //some implementation
    }
    class B
    {
        //some implemntation
    }
}

namespace N2
{
    class A
    {
        //slightly different implementation
    }
    class B
    {
        //slightly different implementation
    }    
}

Obviously we can’t use both assemblies together –

And the resolution is, to use fully qualified class names. When refactoring 1000s of lines of code which uses N1 namespace classes. Decision is made once at the startup of process, whethere N1 has to be used or N2.

Something a bit more advanced than conditional compilation feature in C++

#ifdef debug
#include <N1.h>
#elif
#include <N2.h>
#endif

Sorry if it sounds impossible, but out of my curiosity I wonder is it possible to do –

if (...)
    {
        using N1; 
    }
else
    {
        using N2;
    }
  • 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-11T16:22:57+00:00Added an answer on June 11, 2026 at 4:22 pm

    The using-based approach you are describing will not work, however. “Using a namespace” is really just a compile time construct, so it has no effect on the runtime behavior. At runtime, the fully qualified types are used.

    One typical approach to handling this is to use form of IoC, via a library like MEF.

    If you make your types in both namespaces derive from the same base classes, or implement the same interfaces, you can [Export] the types from two separate assemblies. The decision of which assembly to compose can be made at runtime. This allows you to then [Import] types as needed, and you’ll get the appropriate types.

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

Sidebar

Related Questions

Consider the following code: #include <iostream> using namespace std; class Test { static int
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider following code: namespace base { class Base { protected: class Nested { protected:
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
Consider the following code: // MyClass.h @interface MyClass @property NSInteger Value; @end //MyClass.m @implementation
Consider the following code :- public class UsingWait1{ public static void main(String... aaa){ CalculateSeries
Consider the following code in a DLL: public class ReceivingClass { private Assembly myAssembly;
This is rather interesting, I think. Consider following code, both the window.onload and body

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.