MQL5 - "pointer to this function type is not supported yet"

 

I'm guessing the error message means exactly what it says.

Can anyone suggest a clean work-around?

#property strict

typedef bool (*SignalFn)(void);

// Global function definitions
bool IsBuySignal() { return true; }
bool IsSellSignal() { return false; }

// Create an abstract base class
class CStrategy
{
public:
        virtual bool IsBuySignal(void)=0;
        virtual bool IsSellSignal(void)=0;
};

// Derived class
class Strat1 : public CStrategy
{
public:
        // Implement the required functions
        bool IsBuySignal(void) { return true;}
        bool IsSellSignal(void) { return true;}
};

void OnStart()
{
        // Global functions work as expected
        SignalFn ptrSignalFn;                           // pointer to a signal function
        ptrSignalFn = IsBuySignal;
        if ( ptrSignalFn() ) { Print("Is Buy"); }

        // instantiate a class
        Strat1 strat1;

        // Either of these fails to compile
        ptrSignalFn = strat1.IsBuySignal;                       // pointer to this function type is not supported yet
        //ptrSignalFn = Strat1::IsBuySignal;            // pointer to this function type is not supported yet
}
 

A clean workaround will depend of your real use case. A suggestion :

#property strict

class CStrategy;
typedef bool (*SignalFn)(CStrategy*);

// Global function definitions
bool IsBuySignal(CStrategy*ptr) { return ptr.IsBuySignal(); }
bool IsSellSignal(CStrategy*ptr) { return ptr.IsSellSignal(); }

// Create an abstract base class
class CStrategy
{
public:
        virtual bool IsBuySignal(void)=0;
        virtual bool IsSellSignal(void)=0;
};

// Derived class
class Strat1 : public CStrategy
{
public:
        // Implement the required functions
        bool IsBuySignal(void) { return true;}
        bool IsSellSignal(void) { return true;}
};

void OnStart()
{
        // instantiate a class
        Strat1 strat1;

        // Global functions work as expected
        SignalFn ptrSignalFn;                           // pointer to a signal function
        ptrSignalFn = IsBuySignal;
        if ( ptrSignalFn(&strat1) ) { Print("Is Buy"); }
}
 
Alain Verleyen:

A clean workaround will depend of your real use case. A suggestion :

It's a thought. Thanks for the suggestion.
 
Alain Verleyen:

A clean workaround will depend of your real use case. A suggestion :

Is it possible to create a pointer to a class method Iint?

class Fer{public:
int Iint(int q){return 18;};
Fer(){}~Fer(){}
};
Reason: