Platform, default, and cli Namespaces (C++ Component Extensions)

A namespace implicitly qualifies the names of language elements so the names do not conflict with user-defined symbols in existing source code.

All Runtimes

Visual C++ provides separate namespaces for sets of similar data types in C++/CX and C++/CLI. A namespace avoids name collisions between identical symbols. For example, a name collision might prevent the compiler from recognizing Context-Sensitive Keywords (C++ Component Extensions).

Windows Runtime

For more information, see Namespaces and type visibility (C++/CX).

Requirements

Compiler option: /ZW

Common Language Runtime

Syntax

using namespace cli;

Remarks

The C++/CLI supports the cli namespace. When compiling with /clr, the using statement in the Syntax section is implied.

The following language features are in the cli namespace:

Requirements

Compiler option: /clr

Examples

Example

The following code example demonstrates that it is possible to use a symbol in the cli namespace as a user-defined symbol in your code. However, once you have done so, you will have to explicitly or implicitly qualify your references to the cli language element of the same name.

// cli_namespace.cpp
// compile with: /clr
using namespace cli;
int main() {
   array<int> ^ MyArray = gcnew array<int>(100);
   int array = 0;

   array<int> ^ MyArray2 = gcnew array<int>(100);   // C2062

   // OK
   cli::array<int> ^ MyArray2 = gcnew cli::array<int>(100);
   ::array<int> ^ MyArray3 = gcnew ::array<int>(100);
}

See Also

Concepts

Component Extensions for Runtime Platforms