-
Notifications
You must be signed in to change notification settings - Fork 160
/
override.cpp
45 lines (37 loc) · 1.05 KB
/
override.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
// https://stackoverflow.com/questions/13880205/is-the-override-keyword-just-a-check-for-a-overridden-virtual-method/54535784#54535784
// https://stackoverflow.com/questions/29145476/requiring-virtual-function-overrides-to-use-override-keyword
#include "common.hpp"
struct Base {
virtual void f() = 0;
virtual void g() = 0;
virtual void h(int) = 0;
void i() {}
};
struct Derived : Base {
void f() override;
void g() override {};
void h(int) {};
#if 1
void h(float) {};
#else
// g++6.4.0: error: ‘void Derived::h(float)’ marked ‘override’, but does not override
void h(float) override {};
#endif
#if 1
void i() {}
#else
// g++6.4.0: error: ‘void Derived::i()’ marked ‘override’, but does not override
void i() override {}
#endif
};
#if 1
void Derived::f() {}
#else
// g++6.4.0: error: virt-specifiers in ‘f’ not allowed outside a class definition
void Derived::f() override {}
#endif
int main() {
Derived derived;
// Yup, it is a valid identifier in normal contexts.
int override = 1;
}