> On Mon, Aug 22, 2011 at 1:36 PM, asif saeed > <[email protected]> wrote: > > > I read the following tutorial yesterday - it creates class > members on stack > > - that is, it does not make them pointers and allocate them > using new(): > > > > http://www.fltk.org/doc-2.0/html/example3.html > > > > I have also gone through examples that create members on > heap - that is, > > the members are pointers - not values/objects. I have read > in docs that > > Fl_Group automatically deletes the children, that you add, > upon exit. What > > is the difference between creating members on stack and on > heap? Don't you > > think creating them on stack will automatically release > them that could > > cause Fl_Group to release non-existing memory?
Why do you think that would happen? If you create the Group and all it's children on the stack, then when the stack unrolls they will all go out of scope together, and there's no problem. If you mix up stack-automatic and heap-allocated widgets together, then you may need to be careful with the way things are allocated and released. But that's not a fltk feature - that's the way C++ works. It's a very sharp tool, but you do need to be careful not to cut yourself at times! > Basically, I don't understand this piece of text in the above link: > > "You can also define the widgets as pointers and have your > constructor call > "new" to define them, this can be more convenient in some cases and is > necessary if you want to repeat or vary the set of widgets." It's not clear what you don't understand there, surely that's just describing what I'd consider the "normal" way of allocating widgets... Fl_Window *my_win = NULL; : : my_win = new Fl_Window(w,h,label); : : SELEX Galileo Ltd Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL A company registered in England & Wales. Company no. 02426132 ******************************************************************** This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ******************************************************************** _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

