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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:16:17+00:00 2026-05-18T10:16:17+00:00

I find that my C++ header files are quite hard to read (and really

  • 0

I find that my C++ header files are quite hard to read (and really tedious to type) with all the fully-qualified types (which goes as deep as 4 nested namespaces). This is the question (all the answers give messy alternatives to implementing it, but that’s not the question): Is there a strong reason against introducing scoped using-directive in structs and classes in the C++ language (while it’s permissible to have scoped using-declaration in functions)?

e.g.

class Foo : public Bar
{
    using namespace System;
    using namespace System::Network;
    using namespace System::Network::Win32::Sockets;
    using Bar::MemberFunc; // no conflict with this

    // e.g. of how messy my header files are without scoped using-directive
    void FooBar(System::Network::Win32::Sockets::Handle handle, System::Network::Win32::Sockets::Error& error /*, more fully-qualified param declarations... */);
};

Since namespace is a keyword, I would’ve thought it’s distinct enough to cause no conflict with the scoped using declaration such as Bar::MemberFunc.

EDIT: Read the question carefully —> I’ve bolded it. Reminder: we’re not discussing how to improve readability of the example here. Suggesting how scoped using-directive could be implemented (i.e. by means of adding keywords / constructs etc.) in the C++ language is NOT an answer (if you could find an elegant way to implement this using existing C++ language standards, then it would of course be an answer)!

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

    Given that using declarations at class scope are not inherited, this could work. The name would only be valid inside that class declaration, or inside the declarations of nested classes. But I think it’s sort of overloading the concept of a class with an idea that should be larger.

    In Java and Python individual files are treated in a special way. You can have import declarations that inject names from other namespaces into the file. These names will (well, not exactly with Python, but it’s too complicated to explain here) only be visible within that file.

    To me that argues for this sort of ability not being tied to a class declaration, but given a scope of its own instead. This would allow injected names to be used in several class declarations if it made sense, or even in function definitions.

    Here is an idea I prefer because it allows these things while still giving you the benefits of a class level using declaration:

    using {
       // A 'using' block is a sort of way to fence names in.  The only names
       // that escape the confines of a using block are names that are not
       // aliases for other things, not even for things that don't have names
       // of their own.  These are things like the declarations for new
       // classes, enums, structs, global functions or global variables.
       // New, non-alias names will be treated as if they were declared in
       // the scope in which the 'using' block appeared.
    
       using namespace ::std;
       using ::mynamespace::mytype_t;
       namespace mn = ::mynamespace;
       using ::mynamespace::myfunc;
    
       class AClass {
         public:
          AClass(const string &st, mytype_t me) : st_(st), me_(me) {
             myfunc(&me_);
          }
    
         private:
          const string st_;
          mn::mytype_t me_;
       };
    // The effects of all typedefs, using declarations, and namespace
    // aliases that were introduced at the level of this block go away
    // here.  typedefs and using declarations inside of nested classes
    // or namespace declarations do not go away.
    } // end using.
    
    // Legal because AClass is treated as having been declared in this
    // scope.
    AClass a("Fred", ::mynamespace::mytype_t(5));
    
    // Not legal, alias mn no longer exists.
    AClass b("Fred", mn::mytype_t);
    
    // Not legal, the unqualified name myfunc no longer exists.
    AClass c("Fred", myfunc(::mynamespace::mytype_t(5));
    

    This is analogous to declaring a block for local variables in a function. But in this case you are declaring a very limited scope in which you will be changing the name lookup rules.

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

Sidebar

Related Questions

I have a very large project with tons of convoluted header files that all
I have header files that have a lot of #define statements like: #define GPSVersion
Is there a way to limit the header files that Boost.Build recursively scans for
I have table with a check-all checkbox in the header which checks all the
I find that, Windows 8 will be highly HTML5 + Javascript based Metro Application
I find that I'm repeating myself alot and that is of course no good.
I find that exports.index = (req, res) -> res.render index, title: Hello compiles to
I find that after running or debugging my application a few times using eclipse,
I find that if there are a lot of classes the compilation time is
I find that writing web apps and WinForm apps generally come out a lot

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.