Chinaunix首页 | 论坛 | 博客
  • 博客访问: 530694
  • 博文数量: 576
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5020
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:47
文章分类

全部博文(576)

文章存档

2011年(1)

2008年(575)

我的朋友

分类:

2008-10-14 15:08:38

?vdtor.cpp

// To compile:
//
//    cl /clr vdtor.cpp
//
#include 
#include 

#using 
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;
}

?IL for Finalize Method
.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

?Integral Types

CLR ClassDescriptionCLS-CompliantVisual Basic C#C++
Int16A 16-bit signed integer.YesShortshortshort
Int32A 32-bit signed integer.YesIntegerintint , long
Int64A 64-bit signed integer.YesLonglong__int64
UInt16A 16-bit unsigned integer. NoUInt16. No built-in type.ushortunsigned short
UInt32A 32-bit unsigned integer.NoUInt32. No built-in type.uintunsigned int,unsigned long
UInt64A 64-bit unsigned integer.NoUInt64. No built-in type.ulongunsigned __int64
IntPtrA 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).YesIntPtr. No built-in type.IntPtr. No built-in type.IntPtr. No built-in type.
UIntPtrAn 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).NoUIntPtr. No built-in type.UIntPtr. No built-in type.UIntPtr. No built-in type.



--------------------next---------------------

阅读(493) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~