-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
43 lines (28 loc) · 937 Bytes
/
main.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
#include <logic.h>
// init in main cpp. step <1/3>
DYNAMIC_INIT
class MyLogic : public Logic {
public:
virtual void really_do_something() {
printf("i am the one in the back.");
}
};
// register dynamic class. step <2/3>
DYNAMIC_REGISTER(MyLogic)
// if we use in other file, define below.
//DYNAMIC_USE
int main() {
// add. step <3/3>
dynamic_add(MyLogic);
DynamicBase *obj;
// get, class. of course we can get from where didn't know Mylogic class except its base class.
// @see line:18
dynamic_get(std::string("Mylogic"), obj);
if (obj) {
// here is the point, we just know the base class. Logic.
Logic *lc = (Logic*)obj;
lc->do_something(); // here, -----> will call really_do_something() in Mylogic class, where we didn't know the class name. MyLogic.
}
// very simple, have fun.
reutnr 0;
}