Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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.

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:

Compiler option: /clr

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);
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft