Re: Timer start registration breaks the gtk_main()

On Sat, 26 Mar 2011 20:27:04 -0700 (GMT-07:00)
ikorot earthlink net wrote:
> >Yes, ReadData() is a non-static class member function.  Illegal casts
> >to avoid compilation failure has, as you can tell, not saved you
> >here.
> So in order to fix it, I need to use 'static' in front of 'void
> ReadData()'?

You should most properly use a plain function with C linkage as the
callback. If you want to access instance (non-static) data you need to
pass in an instance pointer; and if it needs to access private data it
should be made a friend.

Basically what you want is something like this:

// *** header file ***
extern "C" gboolean cframe_read_data(void* data);

class CFrame {
  gboolean ReadData();

// *** implementation file ***

gboolean cframe_read_data(void* data) {
  return static_cast<CFrame*>(data)->ReadData();

int main() {
  CFrame* cf = new CFrame;
  g_timer_add_seconds( 1, cframe_read_data, cf);


This is all very basic C/C++


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