-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoly3.h
69 lines (55 loc) · 1.2 KB
/
Poly3.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
class VMT1PolymorphismDemo
{
class Dog
{
public:
char* name; // 4
int age; // 4
void Guard()
{
cout << "Dog::Guard\n";
}
void Bark()
{
cout << "GAV GAV\n";
}
int Sum(int x, int y)
{
return x + y;
}
static void Print()
{
cout << "Dog::Print\n";
}
};
public:
static void Test()
{
cout << "Ðàçìåð â áàéòàõ òèïà Dog: ";
cout << sizeof(Dog) << "\n";
Dog d;
cout << "Àäðåñ îáúåêòà d òèïà Dog: ";
cout << &d << " (" << (int)&d << ")\n";
cout << "Àäðåñ ïåðâîãî ïîëÿ îáúåêòà d: ";
cout << &d.name << " (" << (int)&d.name << ")\n";
cout << "Àäðåñ âòîðîãî ïîëÿ îáúåêòà d: ";
cout << &d.age << " (" << (int)&d.age << ")\n";
cout << "Àäðåñ ñòàòè÷åñêîãî ìåòîäà êëàññà Dog: ";
cout << &Dog::Print << " (èëè ";
cout << &d.Print << ")\n";
cout << "Àäðåñ îáû÷íîãî ìåòîäà êëàññà Dog: ";
void (Dog:: * memfunc_ptr)() = &Dog::Guard;
int (Dog:: * psum)(int,int) = &Dog::Sum;
auto test = &Dog::Sum;
auto cheat = &Dog::Bark;
cout << memfunc_ptr << "\n";
Dog* doge = new Dog;
(doge->*memfunc_ptr)();
int result = (doge->*psum)(5, 10);
cout << result << "\n";
//doge->Sum(1, 2);
doge->Bark();
}
};
// VMT1PolymorphismDemo::Test();