Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

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 (C++ Component Extensions). Namespaces are used by the compiler but are not preserved in the compiled assembly.

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


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);
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.