New C++ Language Features
In Visual C++ 2005 Visual C++ 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 ANSI/ISO C++; it is standardized under the Ecma C++/CLI Specification. 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 are still available, but as a deprecated feature under /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.
Keyword | Context sensitive | Purpose | Reference |
---|---|---|---|
|
No |
Defines a CLR reference class |
|
|
No |
Defines a CLR value class |
|
|
No |
Defines a CLR interface |
|
|
No |
Defines a CLR enumeration |
|
|
Yes |
Defines a CLR property |
|
|
Yes |
Defines a CLR delegate |
|
|
Yes |
Defines a CLR event |
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 |
|
|
No |
Indicates that a function is not an override of a base class version |
|
|
Yes |
Indicates that a method must be an override of a base-class version |
|
|
Yes |
Prevents classes from being used as base classes |
Keywords for Generics
The following keywords have been added to support generic types. For more information, see Generics (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 |
|
|
No |
Enumerate elements of a collection. |
|
|
No |
Allocates types on the garbage-collected heap |
|
|
Yes |
Indicates a member can only be initialized at declaration or in a static constructor |
|
|
Yes |
Creates a literal variable |
|
|
No |
Indicates that a handle or pointer does not point at an object |
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 |
|
|
Points to data inside reference types. |
|
|
Points to CLR reference types to temporarily suppress the garbage collection system |
|
|
Determines and executes the optimal casting method for CLR types |
|
|
Retrieves a System.Type object describing the given type or object |
New Operators
Two new operators have been added to Visual C++ to support garbage-collected programming.
Operator | Purpose | Reference |
---|---|---|
|
Indicates a handle to an object located on the garbage-collected heap |
|
|
Indicates a tracking reference |
More CLR Constructs
In addition to keywords and language constructs, this reference section includes the following CLR programming constructs.
Topic | Description |
---|---|
Enables the use of C++ keywords as identifiers |
|
Lists the CLR types used in place of C++ integral types |
|
appdomain __declspec modifier |
__declspec modifier that mandates static and global variables exist per appdomain |
Describes how C-style casts are interpreted |
|
__clrcall calling convention |
Indicates the CLR-compliant calling convention |
__cplusplus_cli |
|
Describes how to define your own CLR attributes. |
|
Provides an overview of exception handling |
|
Demonstrates how member functions can override arbitrary members |
|
Discusses how a client assembly can access all types in an assembly component. |
|
Demonstrates the conditions where values types are boxed |
|
Discusses how to detect characteristics of types at compile time. |
|
managed, unmanaged pragmas |
Demonstrates how managed and unmanaged functions can co-exist in the same module |
process __declspec modifier |
__declspec modifier that mandates static and global variables exist per process |
Demonstrates the CLR version of run-time type information |
|
Discusses compiler conversion of string literals to String. |
|
Allows you to move a type in a shipping assembly to another assembly, such that, client code does not have to be recompiled. |
|
Demonstrates use-defined attributes |
|
Imports external assemblies |
|
Explains XML-based code documentation using /doc (Process Documentation Comments) (C/C++) |
See Also
Reference
Breaking Changes in the Visual C++ 2005 Compiler