C++将指针转换为静态方法

Tro*_*opE 5 c++ methods static compiler-errors interrupt

我很久没有写C++代码了; 但是现在我必须研究德州仪器F28335 DSP,我正在尝试从C迁移到C++.我有以下代码尝试使用类的静态方法初始化中断服务例程:

//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;
 }
Run Code Online (Sandbox Code Playgroud)

编译时我得到以下内容:

错误:类型为"void(*)()"的值无法分配给"PINT"类型的实体

我想我错过了一些演员.

sel*_*bie 2

我认为根本问题是在 p 的赋值的 RHS 前面加上 & 符号。此外,“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;
}
Run Code Online (Sandbox Code Playgroud)