相关疑难解决方法(0)

在类中使用OpenGL glutDisplayFunc

我已经创建了一个C++类(myPixmap)来封装OpenGL GLUT工具包执行的工作.display()该类的成员函数包含设置GLUT所需的大部分代码.


void myPixmap::display()
{
    // open an OpenGL window if it hasn't already been opened
    if (!openedWindow)
    {
        // command-line arguments to appease glut
        char *argv[] = {"myPixmap"};
        int argc = 1;
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(640, 480);
        glutInitWindowPosition(30, 30);
        glutCreateWindow("Experiment");
        glutDisplayFunc(draw);
        glClearColor(0.9f, 0.9f, 0.9f, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glutMainLoop();

        openedWindow = true;
    }  
}
Run Code Online (Sandbox Code Playgroud)

传递给的显示函数glutDisplayFunc()是该类的另一个成员函数:


void myPixmap::draw(void)
{
    glDrawPixels( m,n,GL_RGB,GL_UNSIGNED_BYTE, pixel );
}
Run Code Online (Sandbox Code Playgroud)

但是,Mac OS X 10.6.4上的gcc 4.2.1拒绝编译此代码,声称:

argument of type 'void (myPixmap::)()' …

c++ opengl compiler-errors class

27
推荐指数
1
解决办法
2万
查看次数

如何定义指向静态成员函数的函数指针?

#include "stdafx.h"

class Person;
typedef void (Person::*PPMF)();

// error C2159: more than one storage class specified
typedef static void (Person::*PPMF2)();  

class Person
{
public:
    static PPMF verificationFUnction()
    { 
        return &Person::verifyAddress; 
    }

    // error C2440: 'return' : cannot convert from 
    // 'void (__cdecl *)(void)' to 'PPMF2'
    PPMF2 verificationFUnction2()               
    { 
        return &Person::verifyAddress2; 
    }
private:
    void verifyAddress() {}

    static void verifyAddress2() {}
};

int _tmain(int argc, _TCHAR* argv[])
{
    Person scott;

    PPMF pmf = scott.verificationFUnction();
    (scott.*pmf)();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题:我需要定义一个函数指针PPMF2来指向一个静态成员函数verifyAddress2.我该怎么做?

#include "stdafx.h"

class …
Run Code Online (Sandbox Code Playgroud)

c++

26
推荐指数
2
解决办法
3万
查看次数

标签 统计

c++ ×2

class ×1

compiler-errors ×1

opengl ×1