Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Cpp Namespace

Shulou Source: shulou.com Published: 2022-06-01 03:33:46 09月28日 Update

1. All identifiers in namespace censor + are defined in a namespace called std, and namespaces are the various visible ranges of identifiers that control their scope.

2.std is the standard namespace of C++. Identifiers in the C++ standard library are defined in std, such as iostream,vector.

3.using namespace std; means to use the identifiers in the C++ standard library.

4. In order to solve the conflict of large program identifiers

5. Use the entire namespace: using namespace name

Use the variable in the namespace: using name::variable

Variable that uses the default namespace: variable

All identifiers in the default namespace can be used directly by default

6. An error will be reported if you directly use the identifier of the namespace instead of the namespace, as shown in the following figure

7. In the following two cases, @ refers to the variable @ 2 through the namespace plus a double colon to indicate the use of the namespace.

8. For the definition and use of namespaces, see the following code

1 # include 23 namespace Spaceone 4 {5 int a = 10; 6} 7 8 namespace Spacetwo 9 {10 int a = 50 X 11 namespace Spacethree12 {13 struct date14 {15 int year;16 int month;17 int day;18}; 19} 20} 21 22 23 24 void main () 25 {26 using namespace Spaceone;27 28 using Spacetwo::Spacethree::date 29 30 std::cout

Tags: Spaces identifiers identifiers variables standards situations libraries codes actions colons that is programs results ranges problems facets reports conflicts controls Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei Shulou Information Microsoft macOS