设为首页 加入收藏

TOP

C++类机制的实现细节(一)
2013-04-10 11:54:10 来源: 作者: 【 】 浏览:732
Tags:机制 实现 细节

  为了搞清楚VC中类的实现专门写了一个最简单的类,用来观察它的实现过程,代码如下:

  // test.cpp : Defines the entry point for the console application.

  //

  #include "stdafx.h"

  #include "CTest.h"

  int main(int argc, char* argv[])

  {

  CTest aTest;

  aTest.a(1,2);

  return 0;

  }

  // CTest.h: interface for the CTest class.

  //

  //////////////////////////////////////////////////////////////////////

  #if !defined(AFX_CTEST_H__2CCCDCFC_6C3A_48BC_9CD0_E7A8E63431D9__INCLUDED_)

  #define AFX_CTEST_H__2CCCDCFC_6C3A_48BC_9CD0_E7A8E63431D9__INCLUDED_

  #if _MSC_VER > 1000

  #pragma once

  #endif // _MSC_VER > 1000

  class CTest

  {

  public:

  CTest();

  virtual ~CTest();

  public:

  void b();

  void a(int one,int two);

  };

  #endif // !defined(AFX_CTEST_H__2CCCDCFC_6C3A_48BC_9CD0_E7A8E63431D9__INCLUDED_)

  // CTest.cpp: implementation of the CTest class.

  //

  //////////////////////////////////////////////////////////////////////

  #include "stdafx.h"

  #include "CTest.h"

  //////////////////////////////////////////////////////////////////////

  // Construction/Destruction

  //////////////////////////////////////////////////////////////////////

  CTest::CTest()

  {

  }

  CTest::~CTest()

  {

  }

  void CTest::b()

  {

  printf("b is be called by a");

  }

  void CTest::a(int one,int two)

  {

  printf("call b");

  b();

  }

  下面是相应的反汇编代码:

  --- D:myown est est.cpp ------------

  1:  // test.cpp : Defines the entry point for the console application.

  2:  //

  3:

  4:  #include "stdafx.h"

  5:  #include "CTest.h"

  6:

  7:  int main(int argc, char* argv[])

  8:  {

  00401050  push    ebp

  00401051  mov     ebp,esp

  00401053  push    0FFh

  00401055  push    offset __ehhandler$_main (00410c89)

  0040105A  mov     eax,fs:[00000000]

  00401060  push    eax

  00401061  mov     dword ptr fs:[0],esp

  00401068  sub     esp,48h

  0040106B  push    ebx

  0040106C  push    esi

  0040106D  push    edi

  0040106E  lea     edi,[ebp-54h]

  00401071  mov     ecx,12h

  00401076  mov     eax,0CCCCCCCCh

  0040107B  rep stos  dword ptr [edi]

  9:    CTest aTest;

   

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇求字符串的长度并返回 下一篇逆向角度看C++的析构函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: