What does namespace mean? What does namespace do?

云罗郡主
Release: 2018-11-23 14:41:27
Original
16435 people have browsed it


What does namespace mean? What does a namespace do? For those who have just come into contact with namespaces, they may not understand it very well. Let’s summarize what namespaces are?

What does namespace mean? What does namespace do?

1: What does namespace mean?

In many languages, there is the term namespace. In fact, it is for It is designed to prevent problems caused by different people writing. We can also say that there are the same file names under different folders, but the file names will not appear. Namespaces can put variables into the space, and The same name can also be used in other spaces.

2: What is the role of namespace

Namespace is also often referred to as a folder, mainly to allow us to find files and identify files. In CS language, we use namespace to represent namespace. Namespace refers to visible identifiers, and these identifiers are all in namespace. Let's use a case to describe the role of namespace.

Suppose we use the variable score in company a, and we use the variable score in company b. Company b has a group c, but we must first use the score variable of company b, then use the score variable of company a, and finally How can we achieve this using c from company b? The method is as follows:

#include<iostream>
#include"A.cpp"
#include"B.cpp"
using namespace std;
int main()
{
    {                                    //B声明在此范围有效
        using B::score;
        cout<<score<<endl;
    }
    {                                    //A声明在此范围有效
        using A::score;
        cout<<score<<endl;
    }
    {                                    //C声明在此范围有效
        using B::C::score;
        cout<<score<<endl;
    }
    return 0;
}
Copy after login

What does the above mean for namespace? A full introduction to the role of namespaces. If you want to know more about Html5 tutorial, please pay attention to the php Chinese website.



The above is the detailed content of What does namespace mean? What does namespace do?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!