-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (42 loc) · 1.48 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
/**
* Author: https://github.com/infojg9
* MIT/BSD Redistributable License
*/
#include <iostream>
#include "CGenericDelegater.h"
using namespace std;
/// Delegation Test class
class DelegatorTest {
public:
int display(int iParam1) {
cout<<__func__<<" iParam1: "<<iParam1<<endl;
return iParam1;
}
int display2(int iParam2) {
cout<<__func__<<" iParam2: "<<iParam2<<endl;
return iParam2;
}
};
int main() {
DelegatorTest obDelegatorTest;
/// Use compiler flag for target specific selection: -DGENERIC_DELEGATE_ON
#ifdef GENERIC_DELEGATE_ON
/// Explicit delegation call: convention 1: longer but simple
auto obGenDelegate = CGenericDelegater<int, int>::makeDelegation
<DelegatorTest, &DelegatorTest::display>(&obDelegatorTest);
auto obGenDelegate2 = CGenericDelegater<int , int>::makeDelegation
<DelegatorTest, &DelegatorTest::display2>(&obDelegatorTest);
obGenDelegate(7);
obGenDelegate2(12);
cout<<"obGenDelegate==obGenDelegate2: "
<<(obGenDelegate == obGenDelegate2 ? "True" : "False")<<endl;
/// Implicit delegation call: convention 2: short but complex
auto obGenDelegate3 = GENERIC_DELEGATE(&DelegatorTest::display, &obDelegatorTest);
auto obGenDelegate4 = GENERIC_DELEGATE(&DelegatorTest::display2, &obDelegatorTest);
cout<<"obGenDelegate3==obGenDelegate3: "
<<(obGenDelegate3 == obGenDelegate3 ? "True" : "False")<<endl;
obGenDelegate3(20);
obGenDelegate4(30);
#endif
return 0;
}