Figure 2 vdtor.cpp
// To compile:
//
// cl /clr vdtor.cpp
//
#include <tchar.h>
#include <stdio.h>
#using <mscorlib.dll>
using namespace System;
//////////////////
// Managed base class.
//
public __gc class CBase {
public:
CBase()
{
printf("ctor: CBase\n");
}
// virtual keyword unnecessary for managed class because CBase is
// implicitly derived from Object and the dtor is converted to a
// Finalize method, which is virtual.
/*virtual*/ ~CBase()
{
printf("dtor: CBase\n");
}
};
//////////////////
// Managed derived class.
//
public __gc class CDerived : public CBase {
public:
CDerived()
{
printf("ctor: CDerived\n");
}
~CDerived()
{
printf("dtor: CDerived\n");
}
};
//////////////////
// Program entry point.
//
int _tmain()
{
// Create object: note pointer is declared as CBase* but actually
// points to instance of derived class.
CBase* pBase = new CDerived();
// Explicitly delete to see which dtor is called...?
delete pBase;
return 0;
}
.method family virtual instance void Finalize() cil managed {
// Code size 18 (0x12)
.maxstack 1
IL_0000: ldsflda valuetype $ArrayType$0x6e2836de modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) ??_C@_0BA@PPNICPAI@dtor?3?5CDerived?6?$AA@
IL_0005: call vararg int32 modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) printf(int8 modopt([Microsoft.VisualC]Microsoft.VisualC.NoSignSpecifiedModifier) modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier)*)
IL_000a: pop
IL_000b: ldarg.0
IL_000c: call instance void CBase::Finalize()
IL_0011: ret
} // end of method CDerived::Finalize
| CLR Class | Description | CLS-Compliant | Visual Basic | C# | C++ |
|---|---|---|---|---|---|
| Int16 | A 16-bit signed integer. | Yes | Short | short | short |
| Int32 | A 32-bit signed integer. | Yes | Integer | int | int , long |
| Int64 | A 64-bit signed integer. | Yes | Long | long | __int64 |
| UInt16 | A 16-bit unsigned integer. | No | UInt16. No built-in type. | ushort | unsigned short |
| UInt32 | A 32-bit unsigned integer. | No | UInt32. No built-in type. | uint | unsigned int,unsigned long |
| UInt64 | A 64-bit unsigned integer. | No | UInt64. No built-in type. | ulong | unsigned __int64 |
| IntPtr | A signed integer whose size depends on the underlying platform (a 32-bit value on a 32-bit platform and a 64-bit value on a 64-bit platform). | Yes | IntPtr. No built-in type. | IntPtr. No built-in type. | IntPtr. No built-in type. |
| UIntPtr | An unsigned integer whose size depends on the underlying platform (a 32- bit value on a 32-bit platform and a 64-bit value on a 64-bit platform). | No | UIntPtr. No built-in type. | UIntPtr. No built-in type. | UIntPtr. No built-in type. |