Community Goodies: Resource Index for Language Features of C++/CLI

SUMMARY C++/CLI is a self-contained, component-based dynamic programming language that, like C# or Java, is derived from C++; it is a binding of C++ to Microsoft’s .NET programming environment. This article is to give you a brief introduction of the language features of C++/CLI.
CLR Data Types

CLR types are prefixed with an adjective that describes what sort of type it is. The following are examples of CLR data type declarations in C++/CLI.

  • Reference types

      ref class RefClass{...};

      ref struct RefClass{...};

  • Value types

      value class ValClass{...};

      value struct ValClass{...};

  • Interfaces

      interface class IType{...};

      interface struct IType{...};

  • Enumerations

      enum class Day{...};

      enum struct Day{...};

  • Properties

      property int Property_Block

      {

             int get();

             void set(int value)

             {

                    MyInt = value;

             }

     }

  • Delegate
   public delegate void MyDel(…);
  • Event

        public event delegate ^ event_name;

For more information about the CLR Data types used in C++/CLI, see:

Classes and Structs (Managed)

https://msdn.microsoft.com/en-us/library/6w96b5h7.aspx

Interface class

https://msdn.microsoft.com/en-us/library/737cydt1.aspx

enum class

https://msdn.microsoft.com/en-us/library/a6cskb49.aspx

Properties

https://msdn.microsoft.com/en-us/library/es7h5kch.aspx

Delegates:

https://msdn.microsoft.com/en-us/library/3z2x4f55.aspx

Events:

https://msdn.microsoft.com/en-us/library/4b612y2s.aspx

Override Specifiers

The following keywords can be used to qualify override behavior for derivation.

Abstract (https://msdn.microsoft.com/en-us/library/b0z6b513.aspx ),

New (https://msdn.microsoft.com/en-us/library/86hbff6c.aspx ),

Override (https://msdn.microsoft.com/en-us/library/41w3sh1c.aspx ),

Sealed (https://msdn.microsoft.com/en-us/library/0w2w91tf.aspx )

New keywords

gcnew

https://msdn.microsoft.com/en-us/library/te3ecsc8%28v=VS.100%29.aspx

for each, in

https://msdn.microsoft.com/en-us/library/ms177202%28v=VS.100%29.aspx

initonly

https://msdn.microsoft.com/en-us/library/4d8xah36.aspx

literal

https://msdn.microsoft.com/en-us/library/5yzft952.aspx

nullptr

https://blogs.msdn.com/msdnforum/archive/2010/03.aspx

Generics

Generics are parameterized types supported by the common language runtime.

A parameterized type is a type that is defined with an unknown type parameter that is specified when the generic is used. For more information, see

https://msdn.microsoft.com/en-us/library/8z2kbc1y.aspx

Operators

Two operators have been added to Visual C++ to support garbage-collected programming.

^ (Handle to Object on Managed Heap)

https://msdn.microsoft.com/en-us/library/yk97tc08.aspx

% (Tracking Reference)

https://msdn.microsoft.com/en-us/library/8903062a.aspx

Exception Handling

You can use both structured exception handling (SEH) and C++ exception handling under /clr. Under /clr, you can also handle CLR exceptions. A CLR exception is any exception thrown by a managed type. For more information, see

https://msdn.microsoft.com/en-us/library/633chdda.aspx

Type Forwarding

Type forwarding allows you to move a type from one assembly (assembly A) into another assembly (assembly B), such that, it is not necessary to recompile clients that consume assembly A. For more information, see

https://msdn.microsoft.com/en-us/library/ms177220%28v=VS.100%29.aspx

User-Defined Attributes

You can define a custom attribute by defining a type and making Attribute a base class for the type and optionally applying the AttributeUsageAttribute attribute. For more information, see

https://msdn.microsoft.com/en-us/library/yd21828z%28v=VS.100%29.aspx

Implicit Boxing

The Visual C++ compiler now boxes value types to Object. For more information, see

https://msdn.microsoft.com/en-us/library/c53ss7ze%28v=VS.100%29.aspx

XML Documentation

In Visual C++, you can add comments to your source code that will be processed to an .xml file. For more information, see

https://msdn.microsoft.com/en-us/library/ms177226%28v=VS.100%29.aspx

You can learn more about the language features for C++/CLI from the following document:

https://msdn.microsoft.com/en-us/library/xey702bw.aspx