forked from mcpp-community/d2mcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-final-and-override-1.cpp
More file actions
58 lines (45 loc) · 1.05 KB
/
Copy path02-final-and-override-1.cpp
File metadata and controls
58 lines (45 loc) · 1.05 KB
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
// mcpp-standard: https://github.com/Sunrisepeak/mcpp-standard
// license: Apache-2.0
// file: dslings/cpp11/02-final-and-override-1.cpp
//
// Exercise/练习: cpp11 | 02 - final and override
//
// Tips/提示: 修正代码中final的使用错误问题
//
// Docs/文档:
// - https://en.cppreference.com/w/cpp/language/final
// - https://en.cppreference.com/w/cpp/language/override
//
// Auto-Checker/自动检测命令:
//
// d2x checker final-and-override-1
//
#include <d2x/common.hpp>
#include <iostream>
#include <string>
struct A {
virtual int func1() {
return 1;
}
int func2() { return 2; }
};
struct B : A {
int func1() {
return 3;
}
int func2() {
return 4;
}
};
struct C : B {
};
int main() {
B final; // 不要直接修改main函数中的代码
d2x_assert_eq(final.func1(), 3); // B::func1()
d2x_assert_eq(final.func2(), 4); // B::func2()
A *a = &final;
d2x_assert_eq(a->func1(), 3); // B::func1()
d2x_assert_eq(a->func2(), 2); // A::func2()
D2X_WAIT
return 0;
}