C ++ pointer to static method

I have not written C ++ code for a long time; however, now I have to work on Texas Instruments F28335 DSP, and I'm trying to switch from C to C ++. I have the following code that tries to initialize an interrupt service routine with a static class method:

//type definition for the interrupt service routine
typedef interrupt void (*PINT)(void);
//EPWMManager.h
class EPWMManager
{
public:
    EPWMManager();      
    static interrupt void Epwm1InterruptHandler(void);  
};
//EPWMManager.cpp
interrupt void EPWMManager::Epwm1InterruptHandler(void)
{
 //some code to be called on interruption
}   
//main.cpp
int main(void)
{
    PINT p;
    p = &(EPWMManager::Epwm1InterruptHandler);
    return 0;
 }

When compiling, I get the following:

error: value of type "void (*) ()" cannot be assigned to an entity of type "PINT"

I guess I miss some kind of throw.

+5
source share
3 answers

, , RHS p. , "PINT" " " . . , :

// you may have to move "interrupt" keyword to the left of the "void" declaration.  Or just remove it.
typedef void (interrupt *FN_INTERRUPT_HANDLER)(void);

interrupt void EPWMManager::Epwm1InterruptHandler(void)
{
 //some code to be called on interruption
}  

int main(void)
{
    FN_INTERRUPT_HANDLER p;
    p = EPWMManager::Epwm1InterruptHandler; // no ampersand

    // and if for whatever reason you wanted to invoke your function, you could just do this:

   p(); // this will invoke your function.

    return 0;
}
+2

, : , Epwm1InterruptHandler , void

static interrupt void Epwm1InterruptHandler(void);

static interrupt void Epwm1InterruptHandler(void);

p , :

interrupt p;
p = &(EPWMManager::Epwm1InterruptHandler());
0

; typedef interrupt void (* PINT) (void)? .

0

All Articles