Re: add function in main loop



Hello,

On Sat, Oct 04, 2003 at 09:18:41PM +0200, Laurent Houdusse wrote:

     gtk_idle_add((GtkFunction)oDw3D.RenderFrame, NULL);
...
but when i compile, i have an error:
     'type cast' : cannot convert from '' to 'int (__cdecl *)(void *)'

why?? what is the problem?

The problem is that you try to use a C++ object method as a callback.
Either you have to use a regular function (outside an object), or use a
static method. You can from within the callback still access the object
you want by passing it in as the user data part.

Something along these lines:

class dw3D {
        static void RenderFrame_cb (void*); // make void* a gpointer if you wish
        void RenderFrame (void);
};

void dw3D::RenderFrame_cb (void* data) {
        (static_cast<dw3D*> (data))->RenderFrame();
}

// dw3D::Renderframe definition as usual

// in main():
        gtk_idle_add (G_CALLBACK (dw3D::RenderFrame_cb), &oDw3D);


Note that user data passed to callbacks has to be pointers, so it may be
a better idea to declare oDw3D as a pointer-to-object right from the start.


Regards,

Filip

-- 
"The nice thing about standards is that there are so many to choose from.
 And if you really don't like all the standards you just have to wait
 another year until the one arises you are looking for."
        -- Andrew Tanenbaum, "Introduction to Computer Networks"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]