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 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <string>
#include <map>
using namespace std;
template < typename SCH, typename ARG, class Type >
class REDIRECT
{
public:
typedef void(Type::* pt2member) (ARG);
void add(const SCH & occ, pt2member function);
void test(const SCH & occ, Type & myClass, ARG arg);
private:
map < SCH, pt2member > listINS;
};
template < typename SCH, typename ARG, class Type >
void REDIRECT < SCH, ARG, Type >::add(const SCH & occ, pt2member function)
{
listINS[occ] = function;
return;
}
template < typename SCH, typename ARG, class Type >
void REDIRECT < SCH, ARG, Type >::test(const SCH & occ, Type & myClass, ARG arg)
{
if(listINS.find(occ) != listINS.end())
(myClass.*listINS[occ]) (arg);
return;
}
class AFF
{
public:
void go(int d)
{
cout << "Hello ! D = " << d << endl;
}
};
int main()
{
REDIRECT < int, int, AFF > test;
AFF afficher;
test.add(14, & AFF::go);
test.test(14, afficher, 15);
cout << "END !" << endl;
return 0;
} |
Partager