-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_table.cpp
More file actions
28 lines (25 loc) · 837 Bytes
/
v_table.cpp
File metadata and controls
28 lines (25 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
using namespace std;
class Base {
public:
Base () {}
virtual ~Base () { /*cout << "address is " << (int *)&this << endl;*/}
virtual void f() { cout << "base::f" << endl;}
virtual void g() { cout << "base::g" << endl;}
virtual void h() { cout << "base::h" << endl;}
};
int main(int argc, const char *argv[])
{
typedef void (*fun)(void);
//fun = &Base::f;
fun pfun = NULL;
Base b;
cout << "address of v_table :" << (int *)(&b) << endl;
//cout << "address of v_table :" << &b << endl;
cout << "v_table first function" << (int *)*(int *)(&b) << endl;
//cout << "v_table first function" << *(int *)(&b) << endl;
//cout << "real v_table fir func" << (b.*fun)() << endl;
pfun = (fun)((int *)*(int *)(&b));
cout << "pfun add " << pfun <<endl;
return 0;
}