The practical significance of C + + namespaces

Source: Internet
Author: User

The program can not have two function name of the same, but the program is bigger, it is likely to cause two of the same name of the same parameter functions, which will lead to ambiguity and error.

So make a namespace, you can do as long as it is a different space can have the same name as the same parameter function, so that other people to do, you can not look at the previous write what function name, and as long as a new space, you can freely write function name. This makes it easier to maintain the program! This is used in a lot of PHP, and enhanced the use of namespaces, such as: There are many hierarchical namespaces in TP5, the principle is the same.

#include <iostream>
#include <stdlib.h>

int main () {
Std::cout << "inspired programming-c++" << Std::endl;

system("pause");return 0;

}

In the previous C language, there was no std:: These modifications, why?

Because it is a namespace, in this namespace, you can not have a touch of the same function;

C + + is designed to be able to develop larger programs, so it is likely to create a touch of the same function, while increasing the development hassles and maintenance hassles of subsequent participants. So C + + is made up of multiple spaces.

It's like there are multiple universes that don't interfere with each other.

So C + + has a namespace, and STD is the space name; To use something inside a space, you have to indicate which namespace it is.

But every use to write a space name, and a little trouble.

So it provides a simplified approach:

Specify which space to use first.

#include <iostream>
#include <stdlib.h>

using namespace Std;

int main () {
cout << "inspired programming-c++" << Endl;

system("pause");return 0;

}
Same effect

The practical significance of C + + namespaces

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.