Managed Extensions for C++ Syntax Upgrade Checklist

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

For Visual C++ 2005, Visual C++ includes features for targeting virtual machines with garbage collection, such as the .NET Framework. For Visual C++ 2008, support for Managed Extensions for C++ is deprecated, and might be removed entirely in a future release.

Code using Managed Extensions for C++ can still be compiled with /clr:oldSyntax. See /clr (Common Language Runtime Compilation) for more information For more information on using the new syntax, see:

This topic lists the syntactic differences between Managed Extensions for C++ and the new Visual C++ syntax.

To Update Managed Extensions for C++ Code

  • Remove #using <mscorlib.dll>. (This assembly is now referenced by default.)

  • Replace __gc class with ref class.

  • Replace __gc struct with ref struct.

  • Replace __value class with value class.

  • Replace __value struct with value struct.

  • Remove default constructors from value classes. (Default constructors for value types are allowed in Managed Extensions for C++, but the nature of the CLR prevents them from being called reliably, so this feature has been removed.)

For more information about reference and value types, see Classes and Structs (Managed).

  • Replace __gc __interface with interface class.

For more information about the interface keyword, see interface class.

  • Replace __abstract with abstract, and move it after the class name. For more information, see abstract (Visual C++).

  • Replace __sealed with sealed, and move it after the class name. For more information, see sealed.

  • Replace __property with property, combine the get and set methods into a single property block, and remove the trailing underbar/name suffix from these accessors. For simple properties, the accessors need not be defined explicitly. The syntax for indexed properties requires bracket pairs after the property type. For more information, see, How to: Use Simple Properties and How to: Use Indexed Properties.

  • Replace __event with event (Visual C++).

  • Replace __value enum with enum class.

  • Replace pointers to reference types followed (defined with __gc*) with ^. For more information, see ^ (Handle to Object on Managed Heap).

  • Replace pointers to values types that potentially live in the garbage collected heap with interior_ptr.

  • Replace pointers declared with __pin with instances of pin_ptr, unless a whole object is being pinned, in which case use interior_ptr, and then use pin_ptr on the interior pointer. For Visual C++ 2005, this template is defined in the cli Namespace.

  • Replace new with gcnew.

  • Replace 0 or null with nullptr when used to indicate that a pointer or handle into the garbage collected heap does not indicate an object and when using comparisons to check pointers and handles.

  • Update garbage-collected arrays declared with __gc[] to use the array (Visual C++) type. For Visual C++ 2005, this template is defined in the cli Namespace.

  • Remove all instances of __box. For more information, see Implicit Boxing.

  • Remove the "S" prefix from string literals (the compiler now determines if a string is literal based on the context in which it is used.)

  • Replace the explicit declaration and usage of overloaded operators required in Managed Extensions for C++ (such as op_Addition, op_Subtraction) with the traditional C++ syntax. For more information, see User-Defined Operators and Operator Overloading.

  • Update conversion operators (which use op_Implicit and op_Explicit in Managed Extensions for C++ syntax.) For more information, see User-Defined Conversions.

  • Replace __typeof with typeid.

  • Replace __try_cast with safe_cast. For Visual C++ 2005, this template is defined in the cli Namespace.

  • If you were signing your assembly (also known as giving your assembly a strong name) with the CLR's assembly-signing attributes, you should remove those attributes from your code and instead use the assembly-signing linker options. For more information, see Strong Name Assemblies (Assembly Signing).

See Also

Concepts

Mixed (Native and Managed) Assemblies

Language Features for Targeting the CLR