Chapter 4 tools for large programs (9)

Source: Internet
Author: User

Previous: http://www.bkjia.com/kf/201201/115811.html

17.2.3 untitled namespace
A namespace can enable an unnamed, unnamed namespace to be defined without a name. The Untitled namespace starts with the keyword namespace. After the keyword namespace, It is a block that is bounded by curly brackets.
Unlike other namespaces, an unnamed namespace is defined partial to a specific file and never spans multiple text files.
An untitled namespace can be discontinuous in a given file, but cannot span the file. Each file has its own untitled namespace.
An unnamed namespace is used to declare objects that are partial to a file. Variables defined in an unnamed namespace are created at the beginning of the program and exist until the end of the program.
Names defined in Unnamed namespaces can be used directly. After all, there is no namespace name to limit them. You cannot use the scope operator to reference untitled namespace members.
The names defined in an unnamed namespace are only visible to the files that contain the namespace. If another file contains an unnamed namespace, the two namespaces are irrelevant. Two namespaces can define the same name, and these definitions reference different entities.
The names defined in an unnamed namespace can be found in the scope where the namespace is defined. If an unnamed namespace is defined in the outermost scope of the file, the name of an untitled namespace must be different from that defined in the global scope.
// Namespace2.h
# Ifndef NAMESPACE2_H
# Define NAMESPACE2_H
Namespace andsoft
{
Namespace Namespace2
{
Class Class1;
Class Class2;
}
Namespace
{
Class Class3;
}
}
# Endif
// Namespace2.h
# Ifndef NAMESPACE2_H
# Define NAMESPACE2_H
Namespace andsoft
{
Namespace Namespace2
{
Class Class1;
Class Class2;
}
Namespace
{
Class Class3;
}
}
# Endif // Class3.cpp
# Include "stdafx. h"
# Include "NameSpace2.h"
 
 
Class randsoft: Class3 {
Randsoft: Namespace2: Class2 * c2;
};
// Class3.cpp
# Include "stdafx. h"
# Include "NameSpace2.h"


Class randsoft: Class3 {
Randsoft: Namespace2: Class2 * c2;
}; Before introducing a namespace in Standard C ++, the program must declare the names as static so that they are local to a file. The static declaration in the file is inherited from the C language. In the C language, the local entity declared as static is invisible outside the file that declares it.
C ++ does not approve of static file declaration. A feature that is not supported in future versions is a feature that may not be supported. Do not use namespaces instead of static files.

 

From xufei96's column

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.