X hits on this document





205 / 396


The order in which using-alias-directives are written has no significance, and resolution of the namespace-or-type-name referenced by a using-alias-directive is not affected by the using-alias-directive itself or by other using-directives in the immediately containing compilation unit or namespace body. In other words, the namespace-or-type-name of a using-alias-directive is resolved as if the immediately containing compilation unit or namespace body had no using-directives. In the example

namespace N1.N2 {}

namespace N3 { using R1 = N1;// OK

using R2 = N1.N2;// OK

using R3 = R1.N2;// Error, R1 unknown }

the last using-alias-directive results in a compile-time error because it is not affected by the first using-alias-directive.

A using-alias-directive can create an alias for any namespace or type, including the namespace within which it appears and any namespace or type nested within that namespace.

Accessing a namespace or type through an alias yields exactly the same result as accessing that namespace or type through its declared name. For example, given

namespace N1.N2 { class A {} }

namespace N3 { using R1 = N1; using R2 = N1.N2;

class B { N1.N2.A a;// refers to N1.N2.A R1.N2.A b;// refers to N1.N2.A R2.A c;// refers to N1.N2.A } }

the names N1.N2.A, R1.N2.A, and R2.A are equivalent and all refer to the class whose fully qualified name is N1.N2.A.

9.3.2 Using namespace directives

A using-namespace-directive imports the types contained in a namespace into the immediately enclosing compilation unit or namespace body, enabling the identifier of each type to be used without qualification.

using-namespace-directive: using   namespace-name   ;

Within member declarations in a compilation unit or namespace body that contains a using-namespace-directive, the types contained in the given namespace can be referenced directly. For example:

namespace N1.N2 { class A {} }

192Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views376
Page views376
Page last viewedFri Oct 21 17:32:40 UTC 2016