WEB开发网
开发学院软件开发VC ATL布幔之下的秘密(2) 阅读

ATL布幔之下的秘密(2)

 2006-07-22 22:55:03 来源:WEB开发网   
核心提示: 程序28.#include <iostream>using namespace std;typedef void(*Fun)();class Base {public:Base() {cout << "In Base" << endl

程序28.

#include <iostream>
using namespace std;
typedef void(*Fun)();
class Base {
public:
  Base() {
    cout << "In Base" << endl;
    cout << "Virtual Pointer = " << (int*)this << endl;
    cout << "Address of Vtable = " << (int*)*(int*)this << endl;
    cout << "Value at Vtable 1st entry = " << (int*)*((int*)*(int*)this+0) << endl;
    cout << "Value at Vtable 2nd entry = " << (int*)*((int*)*(int*)this+1) << endl;
    
    // 尝试执行第一个虚函数
    Fun pFun = (Fun)*((int*)*(int*)this+0);
    pFun();
    cout << endl;
  }
  virtual void f1() = 0;
  virtual void f2() = 0;
};
class Drive : public Base {
public:
  Drive() {
    cout << "In Drive" << endl;
    cout << "Virtual Pointer = " << (int*)this << endl;
    cout << "Address of Vtable = " << (int*)*(int*)this << endl;
    cout << "Value at Vtable 1st entry = " << (int*)*((int*)*(int*)this+0) << endl;
    cout << "Value at Vtable 2nd entry = " << (int*)*((int*)*(int*)this+1) << endl;
    cout << endl;
  }
  virtual void f1() { cout << "Drive::f1" << endl; }
  virtual void f2() { cout << "Drive::f2" << endl; }
};
int main() {
  Drive d;
  return 0;
}
现在程序的行为在debug和release模式下仍然不同。在debug模式下,它会显示一个运行时错误的对话框:

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:ATL 之下 秘密

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接