Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ VS 2015和FLTK回调问题_C++_Callback_Visual Studio 2015_Fltk - Fatal编程技术网

C++ VS 2015和FLTK回调问题

C++ VS 2015和FLTK回调问题,c++,callback,visual-studio-2015,fltk,C++,Callback,Visual Studio 2015,Fltk,我正在尝试移动我的FLTK项目,并在VS 2015社区版下进行编译。当我这么做的时候,我得到了一个错误。我有如下代码: #include <Fl/....> .... class CWindow { private: .... Fl_Input *_textInputEditor; .... void _cbTextInput(Fl_Widget *refObject, void *objData) { // Do someth

我正在尝试移动我的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);
        ....
#包括
....
CWindow类
{
私人:
....
Fl_输入*_文本输入器;
....
void\u cbTextInput(Fl\u小部件*重新对象,void*objData)
{
//在触发回调时执行某些操作。
}
公众:
....
void createWindow()
{
....
_textInputEditor=新的Fl_输入(..);
_text输入编辑器->何时(FL\U何时输入\U键);
_textInputEditor->callback((Fl\u callback*)&CWindow::\u cbTextInput,this);
....
当我尝试编译时,我得到一个错误:

错误C2440“类型转换”:无法从“void(\uu thiscall CWindow::*)(Fl\u Widget*,void*)”转换为“Fl\u Callback(\uu cdecl*)”

这段代码在Win7下使用MingW5.x(IDE:C::B)完美地编译


有人能帮我吗?我想要回调用我的CWindow类的私有方法。

签名不正确。\u 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
    ...
}

我之前尝试过这个,但是我得到了这个错误:
错误LNK2001未解析的外部符号\uuuu imp\uuuu strdup
。还有为什么这个在MinGW中编译和工作?它编译是因为强制转换。如果删除强制转换,构建可能会失败。如果使用-Wall进行构建,它会告诉你非法操作的原因。strdup问题我这是一个不同的编译模型:编译的编译模型(MD、MT、MDD或MTD)与库的编译模型不同。谢谢。这是有效的。但是你知道为什么我的旧代码(没有静态)吗在mingw 5.x中编译并构建成功?它在没有强制转换的情况下编译吗?我刚刚用mingw进行了尝试:在没有静态的情况下出现了相同的错误。我使用的是版本4.8.1。