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

ATL布幔之下的秘密

 2006-07-22 22:55:08 来源:WEB开发网   
核心提示: 那么,当类中含有多于一个的虚函数,ATL布幔之下的秘密(6),又会怎么样呢?现在我们希望存取虚函数表中的第二个虚函数,请看下面的程序:程序11. #include <iostream>using namespace std;class Class {virtual void f

那么,当类中含有多于一个的虚函数,又会怎么样呢?现在我们希望存取虚函数表中的第二个虚函数,请看下面的程序:

程序11. #include <iostream>
using namespace std;
class Class {
 virtual void f() { cout << "Class::f" << endl; }
 virtual void g() { cout << "Class::g" << endl; }
};
int main() {
 Class objClass;
 cout << "Address of virtual pointer " << (int*)(&objClass+0) << endl;
 cout << "Value at virtual pointer i.e. Address of virtual table "
  << (int*)*(int*)(&objClass+0) << endl;
 cout << endl << "Information about VTable" << endl << endl;
 cout << "Value at 1st entry of VTable "
  << (int*)*((int*)*(int*)(&objClass+0)+0) << endl;
 cout << "Value at 2nd entry of VTable "
  << (int*)*((int*)*(int*)(&objClass+0)+1) << endl;
 return 0;
}
程序的输出为: Address of virtual pointer 0012FF7C
Value at virtual pointer i.e. Address of virtual table 0046C0EC
Information about VTable
Value at 1st entry of VTable 0040100A
Value at 2nd entry of VTable 0040129E

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

Tags:ATL 之下 秘密

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