Platform, default, and cli Namespaces

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.

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).


using namespace cli;


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:

Compiler option: /clr


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);
© 2015 Microsoft