matthiasm wrote:
> 
> On Jun 27, 2007, at 2:54 AM, Daniel wrote:
> 
>> but what about:
>>
>>       out1 = new Fl_Output( group, .. );
>>       out2 = new Fl_Output( group, .. );
>>       but1 = new Fl_Button( group, .. );
>>       but2 = new Fl_Button( group, .. );
>>
>> The add still takes place in the base widget class constructor,
>> but rather than a system wide static pointer the constructor
>> has a line such as:
>>
>>       widget::widget( widget* parent, .. ) {
>>           ..
>>      parent->add( this );
>>       };  // end widget constructor
> 
> This particular interface was developed about 12 years go. I am not sure 
> anymore, why it was decided to it this way. But to me, the advantage is 
> a less cluttered constructor. Three arguments is a good number for 
> function calls. Any more will tend to generate multi-line wormcode.
> 
> I'd like to ask you back, though: what is bothering you about the 
> current interface? The static variable is not system global, but 
> application global, which is fine as we do not allow multithreading 
> during widget creation for other reasons anyway.
> 
> Oh, I just remembered one reason for the design. You can write classes 
> that have children created in the construtor. This would otherwise not 
> be possible because the 'this' pointer is not available yet. The only 
> alternative would be to put pointers in the class.
> 
> class My_Composite : public Fl_Group {
>   My_Composite(int x, int y, int w, int h, const char *l=0L);
>   Fl_Input  input;
>   Fl_Button upArrow;
>   Fl_Button downArrow;
>   Fl_End    end;
> };
> 
> My_Composite::My_Composite(int x, int y, int w, int h, const char *l)
> : input(x, y, w-20, h, l),
>   upArrow(x+w-20, y, 20, h/2),
>   downArrow(x+w-20, y+h/2, 20, h/2)
> {
> }
> 
> Matthias
> 
> 
> ----
> http://robowerk.com/
> 
> 

Are you certain the 'this' pointer is not available?

example:

    class frame : public widget {
    public:
      frame( ... ) : widget( ... ) {};
    };  // end frame

    class control : public widget {
    public:
      control( widget* p, ... ) : widget( ... ) { ...; p->add( this ); };
    };  // end widget

    class aframe : public frame {
    public:
      aframe( ... ) : frame( ... ) {
        new control( this, ... );
        new control( this, ... );
      };
    };  // end aframe


In the constructor for 'aframe' isn't the 'this' pointer valid for use?
'aframe' called the constructor for it's parent class 'frame' so the
'this' pointer should be usable as a parameter in the constructors of
the child controls.

Forcing the user to remember to include two additional statements seems
counter productive when the same functionality can be done almost
invisibly (from the users point of view) by requiring another parameter
in the constructor.


-Daniel


_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to