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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:46:54+00:00 2026-05-14T01:46:54+00:00

Like : using ::size_t; using ::fpos_t; using ::FILE; In fact it’s a question inspired

  • 0

Like :

using ::size_t; using ::fpos_t; using ::FILE;

In fact it’s a question inspired by the comment under this question:

When is .h not needed to include a header file?

  • 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-14T01:46:54+00:00Added an answer on May 14, 2026 at 1:46 am

    This is called using declaration. There are actually two ways you can use the using keyword. There is a third special form of using declarations used inside class definitions, but i’ll focus on the general using declaration here. (see below).

    • using declaration
    • using directive

    These have two very different effects. A using declaration declares a name to be an alias to another declaration or a set of declarations (if you were to name a set of overloaded functions). The name is declared in the current scope. That is, you can use it inside blocks too

    int main() {
      using std::swap;
      // ...
    }
    

    This is quite useful if you use a name very often locally and you don’t want to prefix it in all uses, and it’s also useful in implementing the swap using argment dependent lookup idiom.

    A using directive names a namespace and does not declare any names. Instead it will modify name lookup to find names that aren’t really declared where it thinks they are. For unqualified name lookup, it find names declared in the enclosing namespace that encloses both the using directive and the target namespace. All names that are declared in the target namespaces will be found:

    int cout;
    int main() {
      using namespace std;
      // cout << 1; ambiguous!
    }
    

    Here, cout will be thought as being declared twice in the global namespace, and causes an ambiguity (:: encloses both main and std). In qualified namelookup, it will build the transitive closure of a namespace with all the namespaces named in using directives.

    using namespace foo;
    
    int main() {
      ::c++; 
    }
    

    c is not only looked up in the global namespace, but also in the namespace foo and in the namespaces that foo has using directives for and so on. If however the global namespace would contain a direct declaration (including a using declaration), that declaration will hide the declarations found indirectly by using directives:

    using namespace foo;
    int c;
    
    int main() {
      ::c++; // not ambiguous!
    }
    

    Using declarations can appear in many places, including inside class definitions. Its meaning is similar to its meaning otherwhere with an important restriction: It declares a name to be an alias to one or more declarations, but the declarations must be members of a base class. This is very useful for making names visible in a derived class that would otherwise be hidden by the same name declared there

    struct base {
      void f();
    };
    
    struct derived : base {
      using base::f; // name "f" declared in derived
      void f(int); // overloads the using declaration
    };
    

    Now you can call d.f(). If there were no using declaration, then name lookup would only find one declaration of f in derived and stop lookup, not delving into the base class scope:

    derived d;
    d.f(); // invalid without the using declaration
    d.f(0); // valid with or without the using declaration
    
    // explicitly starting lookup in base: valid with or without the using declaration
    d.base::f();
    

    It also allows to change the accessibility of base-class members, although you should use that sparingly 🙂

    In practice, i found it useful for making virtual member function re-visible:

    struct base {
      virtual void f();
      virtual void f(int);
    };
    
    struct derived : base {
      // using base::f; would solve it
      virtual void f() { ... }
    };
    

    Oops – now d.f(0); is invalid because name lookup only finds the zero parameter f! The using directive would solve it. Notice that if you alias a function declaration that has the same parameter types and constness as an explicit declaration (like f() in this case), then the explicit declaration will still hide the one that the using declaration is an alias for – so both f() functions won’t conflict in this case.

    An alternative to solve this is using the non-virtual interface idiom

    struct base {
      void f() { do_f(); }
      void f(int) { do_f(0); }
    
    private:
      virtual void do_f();
      virtual void do_f(int);
    };
    
    struct derived : base {
    private:
      virtual void do_f() { ... }
    };
    
    struct derived1 : derived {
    private:
      virtual void do_f(int) { ... }
    };
    

    Now, both d.f(0) and d.f() are valid no matter on what object you call it.

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

Sidebar

Ask A Question

Stats

  • Questions 409k
  • Answers 409k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer They can't see the development server port. It only serves… May 15, 2026 at 7:12 am
  • Editorial Team
    Editorial Team added an answer Following code to list out computers in your domain and… May 15, 2026 at 7:12 am
  • Editorial Team
    Editorial Team added an answer use the insertAfter method: XmlDocument xDoc = new XmlDocument(); xDoc.Load(yourFile);… May 15, 2026 at 7:12 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.