Use of namespace members 17.2.4
Except for functions or other scopes, header files should not contain using instructions or using declarations. The header file containing the using indication or using Declaration in its top-level scope has the effect of injecting the name into the file containing the header file. The header file should only define the name as part of its interface, rather than the name used in its implementation.
1. using statement, repeat briefly
A using declaration only introduces one namespace member at a time, which makes it very correct no matter what name is used in the program.
Using std: vector;
Using std: string;
Using std: vector;
Using std: string; 2. using declared scope
The using declaration can appear in the global scope, local scope, or namespace scope. The using declaration in the class scope is limited to the names defined in the base class of the defined class.
Class Book {
Protected:
Virtual void Method1 () throw (logic_error ){}
};
Class NoteBook: private Book {
Protected:
Using Book: Method1;
};
Class Book {
Protected:
Virtual void Method1 () throw (logic_error ){}
};
Class NoteBook: private Book {
Protected:
Using Book: Method1;
}; 3. namespace alias
The namespace alias Declaration starts with the keyword namespace, followed by (shorter) namespace alias name, followed by =, followed by the original namespace name and semicolon. If the original namespace name is undefined, an error occurs.
A namespace alias can also reference a nested namespace.
Namespace vec = Anders: NameSpace1;
Vec: Class1 c1 ();
Namespace vec = Anders: NameSpace1;
Vec: Class1 c1 (); a namespace can have many aliases, and all aliases and the original namespace names can be used interchangeably.
4. using indication
Like the using declaration, using indicates that the namespace name can be abbreviated. Unlike the using declaration, the using directive cannot control which names are visible-they are all visible.
5. using indication form
Using indicates starting with the keyword using, followed by the keyword namespace, and then the namespace name. If the name is not a defined namespace name, an error occurs.
Using indicates that all names of a specified namespace are visible. The short format name can be used from the using indicator point until the end of the scope indicated by using appears.
Using namespace std;
Using namespace Anders: NameSpace2;
Using namespace std;
Using namespace Anders: NameSpace2; 6. using indication and scope
Using indicates that the alias of a space member name is not declared. On the contrary, it has the effect of raising a namespace member to the nearest scope containing the namespace itself and using indication.
Using indicates that it is used in the namespace implementation file.
From xufei96's column