Skip to content

Clean up "Namespaces and Type Visibility (C++/CX)" topic #5612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions docs/cppcx/namespaces-and-type-visibility-c-cx.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
---
description: "Learn more about: Namespaces and Type Visibility (C++/CX )"
title: "Namespaces and Type Visibility (C++/CX )"
ms.date: "12/30/2016"
ms.assetid: cbc01a3a-3b69-4ded-9c42-ecbf0fd0a00e
title: "Namespaces and Type Visibility (C++/CX)"
description: "Learn more about: Namespaces and Type Visibility (C++/CX)"
ms.date: 12/30/2016
---
# Namespaces and Type Visibility (C++/CX )
# Namespaces and Type Visibility (C++/CX)

A namespace is a standard C++ construct for grouping types that have related functionality and for preventing name collisions in libraries. The Windows Runtime type system requires that all public Windows Runtime types, including those in your own code, must be declared in a namespace at namespace scope. Public types that are declared at global scope or nested inside another class will cause a compile-time error.

A .winmd file must have the same name that the root namespace has. For example, a class that's named A.B.C.MyClass can be instantiated only if it's defined in a metadata file that's named A.winmd or A.B.winmd or A.B.C.winmd. The name of the executable is not required to match the .winmd file name.
A `.winmd` file must have the same name that the root namespace has. For example, a class that's named `A.B.C.MyClass` can be instantiated only if it's defined in a metadata file that's named `A.winmd` or `A.B.winmd` or `A.B.C.winmd`. The name of the executable is not required to match the `.winmd` file name.

## Type visibility

In a namespace, Windows Runtime types—unlike standard C++ types—have either private or public accessibility. By default, the accessibility is private. Only a public type is visible to metadata and is therefore consumable from apps and components that might be written in languages other than C++. In general, the rules for visible types are more restrictive than the rules for non-visible types because visible types cannot expose C++-specific concepts that are not supported in .NET languages or JavaScript.

> [!NOTE]
> Metadata is only consumed at run time by .NET languages and JavaScript. When a C++ app or component is talking to another C++ app or component—this includes Windows components ,which are all written in C++—then no run-time consumption of metadata is required.
> Metadata is only consumed at run time by .NET languages and JavaScript. When a C++ app or component is talking to another C++ app or component—this includes Windows components, which are all written in C++—then no run-time consumption of metadata is required.

## Member accessibility and visibility

Expand All @@ -34,7 +33,7 @@ Use the following access modifiers to control both metadata visibility and sourc

## Windows Runtime namespaces

The Windows API consists of types that are declared in the Windows::\* namespaces. These namespaces are reserved for Windows, and types cannot be added to them. In the **Object Browser**, you can view these namespaces in the windows.winmd file. For documentation about these namespaces, see [Windows API](/uwp/api/).
The Windows API consists of types that are declared in the `Windows::*` namespaces. These namespaces are reserved for Windows, and types cannot be added to them. In the **Object Browser**, you can view these namespaces in the `windows.winmd` file. For documentation about these namespaces, see [Windows API](/uwp/api/).

## C++/CX namespaces

Expand All @@ -44,9 +43,9 @@ The C++/CX define certain types in these namespaces as part of the projection of
|--|--|
| default | Contains the built-in numeric and char16 types. These types are in scope in every namespace and a **`using`** statement is never required. |
| `Platform` | Contains primarily public types that correspond to Windows Runtime types such as `Array<T>`, `String`, `Guid`, and `Boolean`. Also includes specialized helper types such as `Platform::Agile<T>` and `Platform::Box<T>`. |
| `Platform::Collections` | Contains the concrete collection classes that implement the Windows Runtime collection interfaces `IVector`, `IMap`, and so on. These types are defined in a header file, collection.h, not in platform.winmd. |
| `Platform::Collections` | Contains the concrete collection classes that implement the Windows Runtime collection interfaces `IVector`, `IMap`, and so on. These types are defined in a header file, `collection.h`, not in `platform.winmd`. |
| `Platform::Details` | Contains types that are used by the compiler and are not meant for public consumption. |

## See also

[Type System (C++/CX)](../cppcx/type-system-c-cx.md)
[Type System (C++/CX)](type-system-c-cx.md)
2 changes: 1 addition & 1 deletion docs/cppcx/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ items:
items:
- name: Type system overview
href: ../cppcx/type-system-c-cx.md
- name: Namespaces and type visibility (C++/CX )
- name: Namespaces and type visibility (C++/CX)
href: ../cppcx/namespaces-and-type-visibility-c-cx.md
- name: Fundamental types
href: ../cppcx/fundamental-types-c-cx.md
Expand Down