lundi 2 mai 2016

Pointer to function-member

I have a FreeRTOS function xTaskCreate. Simplified declaration looks like

typedef void (*TaskFunction_t)( void* );
unsigned xTaskCreate( TaskFunction_t pxTaskCode );

And there are two classes:

class Super {
    virtual void task(void*params) = 0;
};
class Derived1 : public Derived {
    virtual void task(void*params){ while(1){ blinkLed(1); } }
};
class Derived2 : public Derived { ... ;}

In function init() I select one of derived classes and create its instance. Then want to create task

void init(){
    Super *obj = condition ? new Derived1 : new Derived2;
    xTaskCreate( obj->task ); // WRONG.
}

Please help to write proper code.

Aucun commentaire:

Enregistrer un commentaire