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
|
class REDIRECT
{
public:
typedef void(Type::* pt2member)(string); //Type est un template
void add(const SCH& occ, pt2member function(string)); //voici ma fonction "x", string est l' argument "z"
//est-ce le bon prototype ?
void test(const SCH& occ, Type& myClass, string arg); //l'argument = string arg
private:
map<SCH, pt2member> listINS; //si j' essaye de faire pt2member(string) j' ai une liste d' erreur provenant de la STL...
};
void REDIRECT < SCH, Type >::add(const SCH& occ, pt2member function(string))
{
listINS[occ] = function; //on assigne le pointeur de fonction a son occurence.
//faut-il preciser l' argument (string) ou pas ?
return;
}
void REDIRECT < SCH, Type >:: test(const SCH& occ, Type& myClass, string arg)
{
if(listINS.find(occ) != listINS.end())
(myClass.*listINS[occ])(arg); //est-ce que mon passage d' argument est bon ?
return;
}
//main
//test est une instanciation de redirect
//AFF est une classe externe aynt une fonction go(string arg);
//afficher est une instanciation de AFF
test.add(14, &AFF::go);
test.test(14, afficher, "aha"); |
Partager