Re: [gtk-list] Re: C++ and Gtk
- From: Kenneth Albanowski <kjahds kjahds com>
- To: Brian Stempel <stempel oneimage com>
- cc: gtk-list redhat com, nathan lanfear st hmc edu
- Subject: Re: [gtk-list] Re: C++ and Gtk
- Date: Wed, 27 May 1998 10:53:16 -0400 (EDT)
On Wed, 27 May 1998, Brian Stempel wrote:
> > > only real minus (which IMHO isn't really that big of a deal) is the small
> > > amount of casting to get from a generic callback pointer to, say, your
> > > object instance. To be honest, I haven't done that much with gtk, but I
> > > have done
> > Could you give an example of how you might actually go about doing this?
> > I've got a lot of C++ code that I want to keep and I'd also like to keep
> > using the straight gtk+ API.
>
> So, for instance, the code might look like:
>
> class MyObject
[...]
> void MyObject::signalHandler(GtkWidget *, MyObject *data)
> {
>
> MyObject &myObject = *data;
>
> myObject.myOtherMethod();
>
> }
>
> The idea is that you receive the signal data as a pointer-to-instance,
> and then make a reference from that. You could just as easily receive
> the data as a pointer-to-instance, and then just use the -> operator,
> rather than the . operator, but I prefer the above syntax, and I *believe*
> it's slightly more efficient that way.
I'd be astonished if it were more efficient, as it's the identical
operation -- though the compiler might not be smart enough to figure that
out.
In any case, my only complaint with the described technique is that you
lose the "data" slot, in using it as your 'this' pointer, which requires
no end of pains with set_data and get_data to make up for the loss, and
really causes headaches with the MenuFactory. I assume gtk-- has decent
solutions to all of this.
--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]