Re: Timer start registration breaks the gtk_main()

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

 



On Sat, 26 Mar 2011 20:27:04 -0700 (GMT-07:00)
ikorot@xxxxxxxxxxxxx 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 {
  ...
public:
  ...
  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++

Chris


_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux