Stan wrote:
> I was wondering how setting parent(0) would affect memory management,
> which led to another surprise.  Isn't win2 supposed to get
> destructed in the following?
> 
> ////////////////////////////////////////////////////////////////
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl.H>
> #include <iostream>
> 
> class MyWindow : public Fl_Double_Window {
> public:
>     MyWindow(int x, int y, char const* label = 0)
>             : Fl_Double_Window(x, y, label)
>     {;}
>     ~MyWindow() { std::cout << "Deleted " << label() << std::endl; }
> };
> 
> int main()
> {
>     MyWindow* win1 = new MyWindow(300, 300, "Window 1");
>     MyWindow* win2 = new MyWindow(300, 300, "Window 2");
>     win2->end();
>     // win2->parent(0);
>     win1->end();
>     delete win1;
>     return 0;
> }

        I'm thinking that when you do the parent(0); thing,
        you are basically unparenting one window from the other
        (if they were parented, they wouldn't be separate)
        so you'd have to delete each window separately.

        If you want one to be destructed by the other,
        I think you'd need to keep the pointer to win2
        inside win1, and have win1's dtor take it out.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to