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



On Fri, 16 Apr 1999 13:33:52 +0200, gtk-list@redhat.com (Robert_Gasch/PeopleSoft@peoplesoft.com) wrote:
> I may have a perfectly obvious question, but the answer eludes me and
> my (simplistic) understanding of C++:
> 
> In my program, I do the following:
>      Gtk_Window     win;
>      Gtk_VBox  vbox (TRUE, 5);
>      win.add (vbox);          // OK
> 
> so far so good ... my original code though said:
>      win.add (&vbox);    // note the extra '&'
> 
> while compiles fine (without warnings), but in my
> experience is wrong (and I suspect this line of causing
> a core dump under certain OSs).
> 
> Now looking at the Gtk-- header files, add() seems to expect
> a reference as the first argument:
>      void add (Gtk_Widget &child, ...)
> 
> As thus my question is: why does this compile at all? Shouldn't
> the compiler flag the passing of the vbox pointer as a type
> error?

I don't know Gtk--, but I do know C++.

Maybe there are two add() functions:

  void add(Gtk_Widget &child, ...)
  void add(Gtk_Widget *child, ...)

add() is an overloaded function and everything works as expected.

Another thing is: do you compile with all warnings on? g++ uses the
"-Wall" option, IRIX MipsPRO C++ uses "-fullwarn".


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




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