FLTK logo

Re: [fltk.general] FLTK usage in passing pointers from file to file

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: FLTK usage in passing pointers from file to file Bill Spitzak Feb 26, 2021  
 
The objects should work in your first example. There may be a problem with the destructor assuming other things have not been destroyed.
Generally though when using objects it works better if they are local or local static variables in functions, this defers the constructor until they are first used. Something like this is supposed to work:

main() {
    Fl_Window w1(....);
    some_func(w1);
}

some_func(Fl_Window& w) {
   w.show();
}


On Fri, Feb 26, 2021 at 4:37 AM lifeatt...@gmail.com <lifeattickville@gmail.com> wrote:
>So when I now, as you counciled, declare all the Windows globally such as 
>Fl_Window w1(5,198,600,275,"Tester");

This is why we want to see a program, not "snippets" with text. We will "guess" what you're doing and be at odds ...

I interpreted what you did differently from Greg.  I think you did:

File1:

Fl_Window w1(5,198,600,275,"Tester"); // note: declared and created globally
main() {
   w1.show()
}

File2:
extern Fl_Window w1;

some_func() {
    w1.hide()
}

To me, the issue I think I'm seeing is you are trying to use "objects" and not pointers. I think the error you are getting at program shutdown is FLTK trying to destroy the FL_Window instances you created globally, and that can't be done. FLTK is a C library, not a C++ library, so it's best if you work with pointers.

The approach I would use is:

File1:
Fl_Window *w1;
main() {
  w1 = new Fl_Window(5, 198, 600, 275, "Tester");  // note: declared globally, allocated ON THE HEAP
  w1->hide(); // pointer syntax
}

File2:
extern Fl_Window *w1; // extern pointer

some_func() {
  w1->hide(); // pointer syntax
}

Kevin

--
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/ca5666eb-c141-4048-8742-9b91d3e137fcn%40googlegroups.com.

--
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/CAL-8oAjD%2BNPNzsHzUrYJFdwdnXPevsgtqKKXhEytn5LZCe%2BGrQ%40mail.gmail.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'.