Platform, default, and cli Namespaces (C++/CLI and C++/CX)

A namespace qualifies the names of language elements so the names do not conflict with otherwise identical names elsewhere in the source code. For example, a name collision might prevent the compiler from recognizing Context-Sensitive Keywords. Namespaces are used by the compiler but are not preserved in the compiled assembly.

All Runtimes

Visual Studio provides a default namespace for your project when you create the project. You can manually rename the namespace, although in C++/CX the name of the .winmd file must match the name of the root namespace.

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

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

Component Extensions for .NET and UWP