Bonjour à tous,

Je me pose des question sur la faisabilité d'un tableau de pointeur de fonction et de leur appelle par la suite.

J'ai par exemple le fichier.h suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#ifndef LAUNCHER_H
#define LAUNCHER_H
 
#include <QObject>
 
class Launcher : public QObject
{
 
    Q_OBJECT
 
public:
    Launcher(QObject *parent = 0);
    void load();
 
private:
    typedef void (Launcher::*fptr)();
    typedef struct {
        fptr f;
        QString name;
    } function_t;
 
    void loadFunction1();
    void loadFunction2();
    void loadFunction3();
 
    std::vector<function_t> array = {
        function_t{Launcher::loadFunction1, "Load function 1"},
        function_t{Launcher::loadFunction2, "Load function 2"},
        function_t{Launcher::loadFunction3, "Load function 3"}
    };
 
};
 
#endif // LAUNCHER_H
Quand je veux exécuter ma fonction, j'ai l'erreur suivante : must use '.*' or '->*' to call pointer-to-member function in 'func.Launcher::function_t::f (...)', e.g. '(... ->* func.Launcher::function_t::f) (...)'

Code de l'appelle :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
for (function_t &func : array)
    {
        func.f();
    }
Je ne comprend pas pourquoi cela n'est pas possible. J'ai du louper quelque chose.

Merci d'avance