After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 138266 - Gtk::Main as a singleton and examples are confusing
Gtk::Main as a singleton and examples are confusing
Status: RESOLVED WONTFIX
Product: gtkmm
Classification: Bindings
Component: reference documentation
2.4
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2004-03-27 00:09 UTC by Elijah Newren
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Elijah Newren 2004-03-27 00:09:40 UTC
The examples in the documentation show the declaration of an instance of
Gtk::Main inside main() such as:

   Gtk::Main kit(argc, argv);

Such a declaration led me to believe that more than one could be instantiated. 
I believe I read somewhere that Gtk::Main is a singleton and so this isn't
allowed.  Am I correct, or am I misremembering?  If I am correct, why are
instances allowed to be created like this instead of something like the below
code that makes it clear that it's a singleton.  Am I just misunderstanding
something?

--- Header file ---
class Main {
public:
  Main* getInstance(int& argc, char**& argv, bool set_locale=true);
private:
  Main(int& argc, char**& argv, bool set_locale = true);
  Main* s_instance;
}

--- Code file ---
Main * Main::s_instance = NULL;
Main* Main::getInstance(int& argc, char**& argv, bool set_locale=true)
{
  if (s_instance == NULL)
    s_instance = new Main(argc, argv, set_locale);

  return s_instance;
}
Comment 1 Murray Cumming 2004-03-27 17:01:48 UTC
I don't think it's worth making the syntax so awkward because it's used so often.
I'm not also sure that you can't have 2. I think you can have 2 Glib::Mains.
Comment 2 Murray Cumming 2004-04-23 16:29:22 UTC
Maybe it should be a bit more like Glib::Main - feel free to try patching that
for the future. Closing because it's not really a problem and we can't change it
any time soon anyway.