Re: [gtk-list] Gtk--: Why does this (specific code) compile at all?



Robert_Gasch/PeopleSoft@peoplesoft.com writes:

> so far so good ... my original code though said:
>      win.add (&vbox);    // note the extra '&'
> 
> while compiles fine (without warnings)

Which version of Gtk-- are you compiling with ? There should be an
error with the last one.

> but in my experience is wrong (and I suspect this line of causing a
> core dump under certain OSs).

Yes indeed, because you'll end up deleting the vbox twice.

> Now looking at the Gtk-- header files, add() seems to expect
> a reference as the first argument:
>      void add (Gtk_Widget &child, ...)

It also takes a Gtk_ObjectHandle (not very obvious from reading the
headers, that's because add() is a signal). Gtk_ObjectHandle has a
ctor taking an object ptr, which wasn't explicit at first (it now is).

> As thus my question is: why does this compile at all?

Because the ctor wasn't explicit, so your ptr was silently being
converted to a Gtk_ObjectHandle. (quite a nasty one, uh ? :-)

-- 
					Guillaume.
					http://www.worldnet.fr/~glaurent



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