Visual C++ 2005 includes new syntax for writing applications to target the common language runtime. This topic presents an overview of the new syntax.
The new syntax is not part of the ISO/ANSI C++ standard, but is a set of extensions to C++ standardized under the Ecma C++/CLI Standard. For more information on the new syntax, see the C++/CLI Specification.
This syntax replaces the previous syntax, known as Managed Extensions for C++. Managed Extensions for C++ syntax is still available, but as a deprecated feature under the /clr:oldSyntax compiler option. To port code using Managed Extensions for C++, see Managed Extensions for C++ Syntax Upgrade Checklist.
The new syntax is in effect by default when you use /clr.
For information on other new features in Visual C++, see
CLR Data Type Keywords
The following table lists new keywords that have been added to Visual C++. Note that some keywords consist of two words separated by white space. These aggregate keywords are considered keywords despite the fact that, used separately, they have different meanings. The word ref, for example, used without class is not a keyword and can be used as a regular identifier. Likewise, by itself class denotes a native class. But, used together, ref class defines a common language runtime (CLR) reference type.
Override Specifiers
The following keywords can be used to qualify override behavior for derivation. The new keyword is not new to C++ but is listed here because of the additional context in which it can be used. Some specifiers are also valid for native programming. For more information, see How to: Declare Override Specifiers in Native Compilations.
|
Keyword
|
Context Sensitive
|
Purpose
|
Reference
|
| | Yes | Indicates functions or classes are abstract | abstract (Visual C++) |
| | No | Indicates that a function is not an override of a base class version | new (new slot in vtable) |
| | Yes | Indicates that a method must be an override of a base-class version | override |
| | Yes | Prevents classes from being used as base classes | sealed |
Keywords for Generics
The following keywords have been added to support generic types. For more information, see Generics (Visual C++).
|
Keyword
|
Context sensitive
|
Purpose
|
| | No | Defines a generic type |
| | Yes | Specifies the constraints of a generic typef |
Miscellaneous New Keywords
The following keywords have been added to Visual C++.
|
Keyword
|
Context sensitive
|
Purpose
|
Reference
|
| | Yes | Indicates default exception handlings behavior | Exception Handling under /clr |
| | No | Enumerate elements of a collection. | for each, in |
| | No | Allocates types on the garbage-collected heap | gcnew |
| | Yes | Indicates a member can only be initialized at declaration or in a static constructor | initonly |
| | Yes | Creates a literal variable | literal (Visual C++) |
| | No | Indicates that a handle or pointer does not point at an object | nullptr |
Non-Keyword Language Constructs
The following are language constructs that, while not official keywords, are fundamental to .NET programming. These constructs are implemented as templates. Most are defined in the cli Namespace.
|
Keyword
|
Purpose
|
Reference
|
| | Type for representing CLR arrays | array (Visual C++) |
| | Points to data inside reference types. | interior_ptr |
| | Points to CLR reference types to temporarily suppress the garbage collection system | pin_ptr |
| | Determines and executes the optimal casting method for CLR types | safe_cast |
| | Retrieves a System.Type object describing the given type or object | typeid |
New Operators
Two new operators have been added to Visual C++ to support garbage-collected programming.
More CLR Constructs
In addition to keywords and language constructs, this reference section includes the following CLR programming constructs.
See Also