-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtual6.cpp
executable file
·49 lines (41 loc) · 1.24 KB
/
virtual6.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
class ClassA
{
public:
void sun() { printf("\tClassA sun\n"); }
virtual void mon() { printf("\tClassA mon\n"); }
virtual void tue() { printf("\tClassA tue\n"); }
virtual void wed() { printf("\tClassA wed\n"); }
};
class ClassB
{
public:
void sun() { printf("\tClassB sun\n"); }
virtual void mon() { printf("\tClassB mon\n"); }
virtual void thu() { printf("\tClassB thu\n"); }
};
class ClassC : public ClassA, public ClassB
{
};
class ClassD : public ClassC
{
};
int main(int argc, void **argv)
{
void(**vTable)(ssize_t);
void(**vTable2)(ssize_t);
printf("A:\n");
ClassD * d = new ClassD;
vTable = *(void(***)(ssize_t))d;
vTable2 = ((void(***)(ssize_t))d)[1];
printf(" vTable[0]: %#lx", vTable[0]); vTable[0](0x1000);
printf(" vTable[1]: %#lx", vTable[1]); vTable[1](0x1000);
printf(" vTable[2]: %#lx", vTable[2]); vTable[2](0x1000);
printf(" vTable[3]: %#lx\n", vTable[3]); // vTable[3](0x1000);
printf("\n");
printf(" vTable2[0]: %#lx", vTable2[0]); vTable2[0](0x1000);
printf(" vTable2[1]: %#lx", vTable2[1]); vTable2[1](0x1000);
printf(" vTable2[2]: %#lx\n", vTable2[2]); // vTable2[2](0x1000);
return 0;
};