-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticPolymorphism.cpp
46 lines (40 loc) · 956 Bytes
/
StaticPolymorphism.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
// Last sanity check: 2020-05-18
// Example program
#include <iostream>
#include <string>
using namespace std;
struct TreeNode
{ TreeNode *left, * right; };
template <typename T> class Generic_Parser
{
public:
void parse_preorder(TreeNode *node)
{
if(node)
{
process_node(node);
parse_preorder(node->left);
parse_preorder(node->right);
}
cout<<"Generic_Parser::parse_preorder(): \n";
}
void process_node(TreeNode * node)
{
static_cast<T*>(this)->process_node(node);
}
};
class EmployeeChart_Parser : public Generic_Parser<EmployeeChart_Parser>
{
public:
void process_node (TreeNode *node) //this fct will be used because the one from the parent is virtual
{
cout<<"EmplyeeChart::process_node(): \n";
}
};
int main()
{
TreeNode* root;
EmployeeChart_Parser ep;
ep.parse_preorder(root);
return 0;
}