传递成员函数作为参数

时间:2016-02-08 10:44:57

标签: c++ function pointers static maya

我有一个Maya插件,想要获取timeChanges的事件。但是我需要传递一个我不想成为静态的函数,但这在编译时失败了:

void MyClass::initializeCallbacks()
{
    MDGMessage::addTimeChangeCallback((MMessage::MTimeFunction) &timeChanged,this);
}

void MyClass::timeChanged(MTime tim, MyClass* clientData)
{
    <Code>
}

然后我得到以下编译错误:

must explicitly qualify name of member function when taking its address
  ...&timeChanged,this);
     ^~~~~~~~~~~~
      MyClass::
error: cannot cast from type 'void (MyClass::*)(MTime,
      MyClass *)' to pointer type 'MMessage::MTimeFunction' (aka 'void
      (*)(MTime &, void *)')

如何正确传递我的函数指针?

0 个答案:

没有答案