Re: [gtkmm] adding a widget to a container



Max Vasin a écrit :

Ainsley Pereira wrote:

Hi again,

I'm not quite sure I follow your description, but there are a couple of
things I can point at for you to investigate further:

On Mon, May 03, 2004 at 06:00:26PM +0200, cedric wrote:
so to do this, i ve 2 ptr declared in my Plugin.hh file
  static Gtk::HBox *toolBarModContainer_ptr;
  static Gtk::Toolbar *toolBarModDisplayed_ptr;


If you declare a static, it's visible only to that translation unit
(think of this as the .cc file and all the files it #includes). Putting
a static in a .h file is almost always the wrong thing to do - if two
.cc files include it, you end up with TWO copies of the variable, both
with the same name, but not the same variable. If you're including
Plugin.hh from two different .cc files, and setting the variable in one,
but using it in the other, you're not setting the same variable.

you probably want to declare them `extern'

i have already tried, but i have a compilation error (undefined references to the pointers) when i remove the static keyword in Plugin.hh. if i let the pointers static, then i have a segfault probably due to the multiple variables with the same name (instead one global variable) like Ainsley said. Anyway, i ve never managed to use correctly the extern keyword (but maybe i didn t try enough). that s why i m out of ideas! :-/


(General hint: Always initialise pointers at declaration. If you can't
give them their final value yet, initialise them to 0. If you do that
here, you can at least verify whether what I've described above is
what's happening in your code, by checking if it's still 0 before you
use it.)

And another hint:
It is a good idea to use smartpointers that will check if the pointer isn't 0
and report when you try to dereference a null pointer.

ok, i ll try it too!





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]