VS 2015 和 FLTK 回调问题

VS 2015 and FLTK Callback issue

我正在尝试移动我的 FLTK 项目并在 VS 2015 社区版下编译它。在执行此操作时,我遇到了错误。我有如下代码:

#include <Fl/....>
....
class CWindow
{
private:
    ....
    Fl_Input *_textInputEditor;
    ....
    void _cbTextInput(Fl_Widget *refObject, void *objData)
    {
        // Do something when callback is triggered.
    }
public:
....
    void createWindow()
    {
        ....
        _textInputEditor = new Fl_Input(....);
        _textInputEditor->when(FL_WHEN_ENTER_KEY);
        _textInputEditor->callback((Fl_Callback*)&CWindow::_cbTextInput, this);
        ....

当我尝试编译时,出现错误:

Error C2440 'type cast': cannot convert from 'void (__thiscall CWindow::* )(Fl_Widget *,void *)' to 'Fl_Callback (__cdecl *)

同样的代码在 Win 7 下用 MinGW 5.x 完美编译(IDE: C::B)。

有人可以帮我吗?我想回调我的 CWindow class.

的私有方法

签名不正确。 _cbTextInput 应该是静态的。那么问题将是访问成员变量。

static void _cbTextInput(Fl_Widget *refObject, void *objData)
{
    // No access to member variables so cast it to a CWindow* to get
    // at the member variables
    CWindow* self = (CWindow*) objData;
    self->cbTextInput();

    // Alternatively, if you do not wish to write another routine,
    // you will need to put self-> in front of every member variable
    // you wish to access.  Just personal preference: some people prefer
    // it that way.
}

void cbTextInput()
{
    // This has access to member variables
    ...
}