FLTK logo

Re: [fltk.general] Syntax Variations (My original post seemed to disappear

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Syntax Variations (My original post seemed to disappear roger tunnicliffe Sep 16, 2022  
  Thx for the reply (sorry can't see your name).

I am wondering then what would be the use cases for each particular syntactical version. ie.

When and why would i use this code....
        Fl_Button fltkButton(25, 20, 70, 50, "button1");
             noting it requires fltkButton.labelsize(12);
as opposed to this code....
        Fl_Button *fluidButton = new Fl_Button(25, 80, 70, 50, "button2"); 
            noting it requires fltkButton->labelsize(12);

Thx
Roger Tunnicliffe
Cheers

P.S. The more I play around with FLTK/FLUID the more I like it. Very simple to understand. 
I have my own project (www.languageONE.com.au) and have been looking into a GUI. I am 
hoping FLTK would fit the bill.



On Friday, September 16, 2022 at 5:34:23 PM UTC+10 er...@seriss.com wrote:


On 9/15/22 22:42, roger tunnicliffe wrote:
Hi, new to FLTK (and FLUID) and really like it. Have figured out a few things but not sure why there is syntax variations between what FLUID produces and example code I can find. I do not know much about C++ or ObjectOrientation (I am an assembler programmer) but think it might be more about that then anything else. I've posted the following example:-

    If you mean, for instance, these two ways to declare a button:

        Fl_Button fltkButton(25, 20, 70, 50, "button1");

        Fl_Button *fluidButton = new Fl_Button(25, 80, 70, 50, "button2");

    Both declare instances of a button:

    The first form declares an instance of an Fl_Button class called 'fltkButton'.
    This instance and name has a lifetime up to the closing brace for the block
    of code it's declared in (which is main()). When the closing brace is reached,
    the instance is automatically destroyed. This is similar to declaring a
    variable in C; if you declare 'int x = 0;' it will be created and visible up
    until the closing brace.

    The second form declares a pointer called fluidButton, and initializes it
    to point to an instance of Fl_Button created with 'new'. The instance's
    lifetime makes it available until the pointer is destroyed with 'delete',
    and the pointer's lifetime is only visible until the closing brace, unless
    the pointer is saved somewhere else.
    Both button instances are 'initialized' with the x,y,w,h values and the
    button name ("button1" for the first, and "button2" for the second).
    And due to how FLTK operates, the buttons are automatically parented
    to the window that is declared above the buttons. In fact any FLTK widgets
    created after the declaration of the window will automatically be parented
    to the window, up until the window's end() is invoked, ending the auto-parenting.

    It would help if you're familiar with plain old C, as creating instances of classes
    (e.g. Fl_Button foo(..)) is very much like instancing simple integer variables
    (e.g. int foo = 0;).

    And instancing pointers to classes (e.g. Fl_Button *pfoo = new Fl_Button(..))
    is very similar to instancing pointers to integers (e.g. 'int x = 0; int *px = &x;')

    C++ classes are just more complex objects than an 'int', but are
    created/destroyed in much the same way.

    I know assembly too, and I'm not sure there's an easy way to describe
    the above C and C++ concepts in assembly, as automatic variables
    and variable name scope aren't really built into assembly language,
    though these concepts can kinda/sorta be supported by the assembler,
    and/or limiting variable scope to modules (.obj's) in the same way
    variable scope is limited to {} blocks in C/C++.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/471b3dfe-e4a7-4e88-a8fa-f2374a2493aen%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.