C + + Learning notes (1)

Source: Internet
Author: User

In contrast to the C language, C + + also uses the # include directive for header file inclusion, but unlike the new style header file of C + +, there is no suffix.

However, C + + header files can be added to the. h suffix, which adds no to the problem of namespaces.

In C language for a long time there is no concept of namespace, but in development often encounter such problems:

1, two chip manufacturers of a function name is the same, but the implementation of different functions, but the same function name will be error

2, received a colleague of a piece of code, but found that they have a lot of the same name of the function

Maybe C + + used the concept of command space to solve these problems, for example, if there are two people are the same name in the same room, shouting a name, two people do not know who is shouting, but if let two people in different rooms, then a shout 104 small a out, Then 105 of small B will not come out, which avoids the confusion. Classes and functions, as well as variables, can be considered components and placed in namespaces.

There are three ways to use namespaces:

1, using the use of the compiler instructions, with using namespace xxx;

2. Code that uses namespaces, such as #include<iostream>, that is used when using cout std::cout

3, including #include<iostream.h>, can be used directly cout

In a program, only the first method is generally used, and usually only the class or other parts that need to be used are declared, such as using Std::cout;

C + + Learning notes (1)

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.