X hits on this document

874 views

0 shares

0 downloads

0 comments

206 / 396

Chapter ‎18   Unsafe code

namespace N3 { using N1.N2;

class B: A {} }

Above, within member declarations in the N3 namespace, the type members of N1.N2 are directly available, and thus class N3.B derives from class N1.N2.A.

A using-namespace-directive imports the types contained in the given namespace, but specifically does not import nested namespaces. In the example

namespace N1.N2 { class A {} }

namespace N3 { using N1;

class B: N2.A {}// Error, N2 unknown }

the using-namespace-directive imports the types contained in N1, but not the namespaces nested in N1. Thus, the reference to N2.A in the declaration of B results in a compile-time error because no members named N2 are in scope.

Unlike a using-alias-directive, a using-namespace-directive may import types whose identifiers are already defined within the enclosing compilation unit or namespace body. In effect, names imported by a using-namespace-directive are hidden by similarly named members in the enclosing compilation unit or namespace body. For example:

namespace N1.N2 { class A {}

class B {} }

namespace N3 { using N1.N2;

class A {} }

Here, within member declarations in the N3 namespace, A refers to N3.A rather than N1.N2.A.

When more than one namespace imported by using-namespace-directives in the same compilation unit or namespace body contain types by the same name, references to that name are considered ambiguous. In the example

namespace N1 { class A {} }

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

Document info
Document views874
Page views874
Page last viewedMon Dec 05 19:13:54 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments