A Using Declaration and a Using Directive

A namespace is a scope in which declarations and definitions are grouped together. In order to refer to any of these from another scope, a full qualified name is required. However, repeating the full qualified name over and over again is tedious, error prone and less readable. Instead, a using declaration or a using directive can be used.

A using declaration is a sequence consisting of the keyword using followed by a namespace:: member. It instructs the compiler to locate every occurrence of a certain declaration (type, operator, function, etc.) in the specified namespace, as if the full qualified name were supplied:

 #include   //STL vector; belongs to namespace stdvoid main() {   using std::vector;  //using declaration; every occurrence of vector is looked up in std    vector  vi; //without a using declaration, a full qualified name: std::vector  would be required   //... }//end of main; the above using declaration goes out of scope here

A using directive instructs the compiler to recognize all members of a namespace and not just one. It consists of the following sequence: ‘using namespace’ followed by a namespace-name. For example:

 #include    //STL vector; belong to namespace std#include  //iostream classes and operators are also in namespace stdvoid main() {  using namespace std; //directive; all  and  declarations  now accessible    	  vector   vi;  vi.push_back(10);  cout<
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS