Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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++ 回拨错误C2440_C++_Opengl_Visual Studio 2012_Compiler Errors_Tessellation - Fatal编程技术网

C++ 回拨错误C2440

C++ 回拨错误C2440,c++,opengl,visual-studio-2012,compiler-errors,tessellation,C++,Opengl,Visual Studio 2012,Compiler Errors,Tessellation,我正在尝试使用函数rullsCallback,但我得到了C2440错误。我不知道为什么 代码如下: #define callback void(CALLBACK*)() template<typename T> class Tessellation { private: GLUtesselator *pTess; void CALLBACK tessError(GLenum error) { sendErrorMessage((char *

我正在尝试使用函数
rullsCallback
,但我得到了C2440错误。我不知道为什么

代码如下:

#define callback void(CALLBACK*)()

template<typename T>
class Tessellation
{
private:
    GLUtesselator *pTess;

    void CALLBACK tessError(GLenum error)
    {
        sendErrorMessage((char *)gluErrorString(error), true);
    }


 public:

    void Triangulation3D(T* & point, short numOfPoints)
    {
        pTess = gluNewTess();

        gluTessCallback(pTess, GLU_TESS_ERROR,      (callback)tessError);
    }
};
#定义回调无效(回调*)()
模板
类镶嵌
{
私人:
面筋松弛症;
无效回调错误(格伦错误)
{
sendErrorMessage((char*)GlueErrorString(error),true);
}
公众:
空心三角剖分3D(T*&点,短点)
{
pTess=Glunetess();
麸质回调(pTess,GLU TESS_错误,(回调)TESS错误);
}
};
错误发生在回调函数上:

错误C2440:“类型强制转换”:无法从“重载函数”转换为“void(u stdcall*)(void)”

为什么会出现此编译错误?

Visual Studio上的错误id是一个类型转换错误

代码中的问题是,您试图将类方法
Tessellation::tessError()
作为函数指针传递给
russcallback()
,该函数需要指向全局C风格函数的指针

类方法与自由/全局函数非常不同,您不能将其作为简单函数指针传递,因为它每次都需要一个对象,即
this
指针

问题的解决方案是将
tessError()
声明为静态方法,使其有效地与类内作用域的自由/全局函数相同,如下所示:

template<typename T>
class Tessellation
{
private:

    static void CALLBACK tessError(GLenum error)
    {
        sendErrorMessage((char *)gluErrorString(error), true);
    }
    ...
这种方法唯一的缺点是静态
tessError()
不能再访问类变量。这对你来说似乎不是问题,因为它现在没有这样做,它看起来

gluTessCallback(pTess, GLU_TESS_ERROR, (callback)&Tessellation<T>::tessError);